SYNOPSIS
--------
Windows 7: Incorrect Exception message when trying to create a Socket on a bound port
OPERATING SYSTEM
----------------
Windows 7
FULL JDK VERSION
----------------
java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
PROBLEM DESCRIPTION from LICENSEE
---------------------------------
On Windows 7, if we attempting to create a new Socket on a port that is already bound
we receive an unexpected Exception message:
java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:365)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.<init>(ServerSocket.java:185)
at java.net.ServerSocket.<init>(ServerSocket.java:97)
at Test.main(Test.java:10)
We would expect to se something more like this, which is what we see on Windows XP:
java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:365)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.<init>(ServerSocket.java:185)
at java.net.ServerSocket.<init>(ServerSocket.java:97)
at SocketBindTest.main(SocketBindTest.java:8)
The incorrect Exception message could hinder problem diagnosis for customers.
REPRODUCTION INSTRUCTIONS
-------------------------
1. javac Test.java
2. java Test
TESTCASE
--------
import java.net.*;
public class Test {
public static void main(String[] args) {
try {
System.out.println("Opening first socket on port 5555");
ServerSocket socket1 = new ServerSocket(5555);
System.out.println("Opening second socket on port 5555");
ServerSocket socket2 = new ServerSocket(5555);
System.out.println("Closing second socket on port 5555");
socket2.close();
System.out.println("Closing first socket on port 5555");
socket1.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}