JDK-4995680 : Parsing of Socket Constructor address is buggy in 1.4.2_03 or 1.5beta1 or both.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-02-17
  • Updated: 2004-09-03
  • Resolved: 2004-09-03
Related Reports
Duplicate :  
Description

Name: jl125535			Date: 02/17/2004


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

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

A DESCRIPTION OF THE PROBLEM :
In 1.4.2_03, this executes perfectly ok :-
 
new Socket("192.168.0.1\n",port);
 
in 1.5beta1, the same code causes an Exception to be thrown.
 
Code:java.lang.IllegalArgumentException: URI can't be null.
        at sun.net.spi.DefaultProxySelector.select(DefaultProxySelector.java:93)
 
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:352)
        at java.net.Socket.connect(Socket.java:505)
        at java.net.Socket.connect(Socket.java:455)
        at java.net.Socket.<init>(Socket.java:363)
        at java.net.Socket.<init>(Socket.java:178)
 

 
Is this a bug in 1.5beta1,
or a bug in 1.4.2_03,
or simply a tightening up on the address parameter?

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
execute the code :-

new Socket("192.168.0.1\n",port);

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Depends whether whitespace is allowed in a URI passed to the Socket constructor.
If it is, then I would expect it to work fine, if it isn't I would expect an IllegalArgumentException.
However, 1.5beta1 throws a 'URI can't be null Exception', which is clearly wrong, because the URI isn't null.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.net.*;
public class SocketBug
{
   public static void main(String [] args)
   {
      try
      {
         new Socket("192.168.0.1\n",6969);
      }
      catch(Exception e)
      {
         e.printStackTrace();
      }
   }
}
---------- END SOURCE ----------
(Incident Review ID: 238898) 
======================================================================

Comments
EVALUATION The newline character is kept in the InetAddress hostname, which creates an issue when creating the URI which will be passed to the proxyselector. URI don't allow special characters in hostnames, so the the URI constructor fails throwing an exception, which is ignored in SocksSocketImpl.java. To fix this, either we encode the hostname before construction the URI, or we do some sanity cleanup on it. ###@###.### 2004-02-18 Same issue as 5017871 which has been fixed in Tiger, closing as a duplicate. ###@###.### 2004-09-03
18-02-2004