JDK-5069130 : REGRESSION: IllegalArgumentException: protocol = http host = null
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-06-28
  • Updated: 2006-11-15
  • Resolved: 2006-11-15
Description
Name: gm110360			Date: 06/28/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
When I tried to get the response code of a conection using the HttpUrlConnection class (java 1.5.0) of an specif and valid url ( http://www.scielo.br/gmb.htm )  I got  an Runtime exception.

When I complied and executed the same program with :

java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

I got the error code:  404.

But if  use a browser (Internet Explorer 5 and Mozilla 1.7) I can download the page without problems.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) compile and execute the program with  java 1.5
2) compile and execute the program with  java 1.4.2
3) dowload the page with a browser


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalArgument
Exception: protocol = http host = null
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
urce)
        at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown So
urce)
        at java.net.HttpURLConnection.getResponseCode(Unknown Source)
        at TestURLConnection.main(TestURLConnection.java:12)
Caused by: java.lang.IllegalArgumentException: protocol = http host = null
        at sun.net.spi.DefaultProxySelector.select(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Sour
ce)
        at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.followRedirect(Unknown So
urce)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
urce)
        ... 2 more

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.net.*;

public class TestURLConnection {
	static String MYURL = "http://www.scielo.br/gmb.htm";

	public static void main(String[] args) throws Exception {
		URL url = new URL(MYURL);
		HttpURLConnection connection =
                                                                   (HttpURLConnection)url.openConnection();

		connection.setFollowRedirects(true);
		connection.connect();
		System.out.println("code = " + connection.getResponseCode());
		connection.disconnect();
	}
}
---------- END SOURCE ----------

Release Regression From : 1.4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Incident Review ID: 281500) 
======================================================================

Comments
EVALUATION Since this is not a regression, throwing and exception on that type of URL is the proper course of action. Closing as "Not a defect"
15-11-2006

EVALUATION The first response for the request is 302 found, with a new location indicated by the Location header field. Here's the value: Location: http:/scielo.php?script=sci_serial&pid=1415-4757&lng=en&nrm=iso The problem with the location URI indicated above is that, it's not a legal URI. Since it is meant to be a relative URI, the protocol component of the URI should not be specified. JDK 1.4.2 and 1.5 doesn't handle this kind of illegal URL. Instead, it is treated as an absolute URL. Hence the error. Looks like both IE and Mozilla are more tolerant of this kind of illegal URIs. So the question is "Do we want to support this kind of URLs in order to be compatible with the other browsers?" ###@###.### 2004-06-28 It seems this worked ok in 1.4.0, but not in 1.4.1 nor 1.4.2. Even in 1.4.0 it does not always work. It only works when a proxy is involved. So it is really not a tiger regression. ###@###.### 2004-07-21
21-07-2004