[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug classpath/70661] New: URLConnection throws incorrect exception if a
From: |
guillerodriguez.dev at gmail dot com |
Subject: |
[Bug classpath/70661] New: URLConnection throws incorrect exception if address cannot be resolved |
Date: |
Thu, 14 Apr 2016 10:35:56 +0000 |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70661
Bug ID: 70661
Summary: URLConnection throws incorrect exception if address
cannot be resolved
Product: classpath
Version: 0.99
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: classpath
Assignee: unassigned at gcc dot gnu.org
Reporter: guillerodriguez.dev at gmail dot com
Target Milestone: ---
According to the API specification, the URLConnection.connect() method should
throw an IOException if an error occurs. However in GNU Classpath if the
address can be resolved, an java.nio.channels.UnresolvedAddressException is
thrown instead. UnresolvedAddressException is a subclass of
IllegalArgumentException, not IOException, so this breaks the API contract.
Here is a sample test case:
===
import java.net.URL;
import java.net.URLConnection;
public class UnresolvedAddress
{
public static void main(String args[]) throws Exception
{
URL url = new URL("http", "someinvalidsitename.com", 80,
"index.html");
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
connection.connect();
}
}
===
This results in the following:
===
Exception in thread "main" java.nio.channels.UnresolvedAddressException
at gnu.java.nio.SocketChannelImpl.connect(SocketChannelImpl.java:160)
at gnu.java.net.PlainSocketImpl.connect(PlainSocketImpl.java:281)
at java.net.Socket.connect(Socket.java:463)
at java.net.Socket.connect(Socket.java:414)
at
gnu.java.net.protocol.http.HTTPConnection.getSocket(HTTPConnection.java:721)
at
gnu.java.net.protocol.http.HTTPConnection.getOutputStream(HTTPConnection.java:802)
at gnu.java.net.protocol.http.Request.dispatch(Request.java:292)
at
gnu.java.net.protocol.http.HTTPURLConnection.connect(HTTPURLConnection.java:219)
at UnresolvedAddress.main(UnresolvedAddress.java:11)
===
Note that the JDK does the right thing here:
===
Exception in thread "main" java.net.UnknownHostException:
someinvalidsitename.com
at
java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:175)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:385)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at sun.net.NetworkClient.doConnect(NetworkClient.java:178)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:427)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:213)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:325)
at
sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:955)
at
sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:891)
at
sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:809)
at UnresolvedAddress.main(UnresolvedAddress.java:11)
===
- [Bug classpath/70661] New: URLConnection throws incorrect exception if address cannot be resolved,
guillerodriguez.dev at gmail dot com <=