Run:
---%<---
import java.io.IOException;
import java.net.URL;
public class ProxyIAETest {
public static void main(String[] args) {
connect("http://localhost/nonexistent");
connect("http:///");
}
private static void connect(String url) {
System.out.println("Connecting to: " + url);
try {
new URL(url).openConnection().connect();
} catch (IOException x) {
System.out.println("OK, got expected exception: " + x);
}
}
}
---%<---
I get:
---%<---
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b43)
Java HotSpot(TM) Server VM (build 14.0-b10, mixed mode)
Connecting to: http://localhost/nonexistent
OK, got expected exception: java.net.ConnectException: Connection refused
Connecting to: http:///
Exception in thread "main" java.lang.IllegalArgumentException: protocol = http host = null
at sun.net.spi.DefaultProxySelector.select(DefaultProxySelector.java:164)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:758)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:688)
at ProxyIAETest.connect(ProxyIAETest.java:11)
at ProxyIAETest.main(ProxyIAETest.java:6)
---%<---
(Similar on JDK 5, 6.)
Of course the URL cannot be connected to. But this should result in an IOException of some kind, not an IllegalArgumentException.
---%<---
import java.io.IOException;
import java.net.URL;
public class ProxyIAETest {
public static void main(String[] args) {
connect("http://localhost/nonexistent");
connect("http:///");
}
private static void connect(String url) {
System.out.println("Connecting to: " + url);
try {
new URL(url).openConnection().connect();
} catch (IOException x) {
System.out.println("OK, got expected exception: " + x);
}
}
}
---%<---
I get:
---%<---
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b43)
Java HotSpot(TM) Server VM (build 14.0-b10, mixed mode)
Connecting to: http://localhost/nonexistent
OK, got expected exception: java.net.ConnectException: Connection refused
Connecting to: http:///
Exception in thread "main" java.lang.IllegalArgumentException: protocol = http host = null
at sun.net.spi.DefaultProxySelector.select(DefaultProxySelector.java:164)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:758)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:688)
at ProxyIAETest.connect(ProxyIAETest.java:11)
at ProxyIAETest.main(ProxyIAETest.java:6)
---%<---
(Similar on JDK 5, 6.)
Of course the URL cannot be connected to. But this should result in an IOException of some kind, not an IllegalArgumentException.
- duplicates
-
JDK-8230044 getResponseCode() throws IllegalArgumentException caused by protocol error while following redirect
-
- Closed
-