Name: skT45625 Date: 08/10/2000
java version "1.2.2"
Classic VM (build JDK-1.2.2-001, green threads, sunwjit)
1. Exact steps to reproduce the problem.
Compile and run the following source code : java Test <port>.
Use first a port which is used by some application, say telnet:23 or ssh:22.
Then use some other port which is not used.
2. Java SOURCE CODE that demonstrates the problem,
Source code : Test.java
///////////////////////////////////////////////////////////////////////
import java.net.*;
import java.lang.*;
import java.io.*;
import java.util.*;
public class Test
{
private Socket testSocket;
public Test(String port_str)
{
try
{
String hosts = "notexist.ac.uk;notexist2.ac.fi; notexist3.se";
StringTokenizer tokenizer = new StringTokenizer(hosts, ";");
while(tokenizer.hasMoreTokens())
{
int port = Integer.parseInt(port_str);
try
{
String nexthost = tokenizer.nextToken();
System.out.println("Connecting to host:\"" + nexthost + "\"");
testSocket = new Socket(nexthost, port);
System.out.println("Connected to host:\"" +
testSocket.getInetAddress().toString() + "\"");
}
catch(java.net.ConnectException ce)
{
System.out.println("SocketTest: " + ce);
}
catch(java.net.UnknownHostException uh)
{
System.out.println("SocketTest: " + uh);
}
}
}
catch(Exception e)
{
System.out.println("SocketTest threw: " + e);
}
}
public static void main(String args[])
{
try
{
new Test(args[0]);
}
catch(ArrayIndexOutOfBoundsException ae)
{
System.out.println("Usage: java Test <port>");
}
}
}
///////////////////////////////////////////////////////////////////////
3. Exact text of any error message(s) that appeared.
Connecting to port 22 (used by ssh):
% java Test 22
Connecting to host:"notexist.ac.uk"
SocketTest: java.net.UnknownHostException: notexist.ac.uk
Connecting to host:"notexist2.ac.fi"
SocketTest: java.net.UnknownHostException: notexist2.ac.fi
Connecting to host:" notexist3.se"
Connected to host:" notexist3.se/0.0.0.0"
Connecting to unused port:
% java Test 2233
Connecting to host:"notexist.ac.uk"
SocketTest: java.net.UnknownHostException: notexist.ac.uk
Connecting to host:"notexist2.ac.fi"
SocketTest: java.net.UnknownHostException: notexist2.ac.fi
Connecting to host:" notexist3.se"
SocketTest: java.net.ConnectException: Connection refused
In Linux_JDK_1.2.2_RC4 (works correctly)
$ java Test 22
Connecting to host:"notexist.ac.uk"
SocketTest: java.net.UnknownHostException: notexist.ac.uk
Connecting to host:"notexist2.ac.fi"
SocketTest: java.net.UnknownHostException: notexist2.ac.fi
Connecting to host:" notexist3.se"
SocketTest: java.net.UnknownHostException: notexist3.se
As it can be seen, if the first character of the hostname is whitespace
(\u0020), the UnknownHostException is not thrown but the connection is made
to local host instead. Noticing this feature took quite a time, so I would
really like to see this kind of features removed.
(Review ID: 108247)
======================================================================