-
Bug
-
Resolution: Fixed
-
P3
-
1.1.5
-
1.2beta4
-
x86
-
windows_95
-
Verified
Name: yyC67448 Date: 04/19/98
On Win32 the java.net.SocketException:socket closed is incorectly thrown when
attempt is made to receive a packet with length greater, than receive buffer
length.
Here is the test demonstrating the bug:
-------------------------------- Test.java -----------------------------
import java.net.*;
class test
{
public static void main(String args[])
{
DatagramSocket soc=null;
DatagramSocket server = null;
DatagramPacket pac=null;
InetAddress sin = null;
int port = 0;
int server_port = 0;
byte[] array = new byte[1];
byte array1[] = { 49, 50, 51, 52, 53 };
String str, str1;
try {
sin = InetAddress.getLocalHost();
} catch(Exception e)
{
System.out.println("Can not get local host address :" + e);
System.exit(-1);
}
// Try to create new DatagramSocket instance
try {
soc = new DatagramSocket();
port = soc.getLocalPort();
} catch(SecurityException e)
{
SecurityManager sec = System.getSecurityManager();
if(sec != null)
{
try {
sec.checkListen(port);
System.out.println("Unexpected SecurityException :" + e);
System.exit(-1);
} catch(SecurityException e1)
{
System.out.println("correctly failed to setup test:
SecurityException");
System.exit(0);
}
}
} catch(Exception e)
{
System.out.println("Can not create DatagramSocket instance :" + e);
System.exit(0);
}
// Try to create DatagramTestServer ...
try {
server = new DatagramSocket(server_port);
server_port = server.getLocalPort();
} catch(Exception e)
{
soc.close();
System.out.println("Failed: Can not create DatagramTestServer " + e);
System.exit(-1);
}
pac = new DatagramPacket(array, array.length);
try {
server.send(new DatagramPacket(array1, array1.length, sin, port));
soc.receive(pac);
} catch(SecurityException e)
{
SecurityManager sec = System.getSecurityManager();
if(sec != null)
{
try {
sec.checkConnect(sin.getHostName(), port);
System.out.println("Unexpected SecurityException :" + e);
System.exit(-1);
} catch(SecurityException e1)
{
System.out.println("correctly failed to setup test:
SecurityException");
System.exit(-1);
}
}
} catch(Exception e)
{
soc.close();
server.close();
System.out.println("Failed: Unexpected exception " + e );
System.exit(-1);
}
str = new String(pac.getData());
str1 = new String(array1);
if(str1.startsWith(str))
{
soc.close();
server.close();
System.out.println("Passed.OKAY");
System.exit(0);
}
soc.close();
server.close();
System.out.println("Failed: Send/received data mismatch");
System.exit(-1);
}
}
------------------ Output from the test on Solaris -------------
Passed.OKAY
-----------------------------------------------------------------
------------------ Output from the test on Windows --------------
Failed: Unexpected exception java.net.SocketException: socket closed
-----------------------------------------------------------------
======================================================================