JDK-6328625 : REGRESSION: URLConnection connect method behaves differently
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-09-26
  • Updated: 2011-02-16
  • Resolved: 2005-09-28
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b52)
Java HotSpot(TM) Client VM (build 1.6.0-ea-b52, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Calling the connect method on a URL connection that is formed from a URL that has an invalid URI is behaving differently between 1.5 and 1.6.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the attached code.

Note the space character in 'test parameter'. Calling .toURI on the url variable causes the same exception in both 1.5 and 1.6, but the call to conn.connect() fails in 1.6 and works in 1.5

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the code to work the same as for 1.5
ACTUAL -
The code fails.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IllegalArgumentException: URI can't be null.
        at sun.net.spi.DefaultProxySelector.select(DefaultProxySelector.java:111)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:720)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:650)
        at urltest.Main.<init>(Main.java:29)
        at urltest.Main.main(Main.java:44)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package urltest;
import java.net.URL;
import java.net.URLConnection;

public class Main
{
    public Main()
    {
        try
        {
            URL url=new URL("http://localhost/test?parameter1=test parameter");
            // System.out.println(url.toURI().toString());
            URLConnection conn=url.openConnection();
            conn.connect();
            conn.getInputStream();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static void main(String[] args)
    {
        new Main();
    }
}


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None found yet.

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