FULL PRODUCT VERSION :
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows Server 2008 R2 (6.1.7601), also repeated on Windows 7 64-bit (also 6.1.7601).
EXTRA RELEVANT SYSTEM CONFIGURATION :
IPv6 is disabled in the network adapter.
A DESCRIPTION OF THE PROBLEM :
This looks like it may be a recurrence of JDK-6458027 or something similar. After reading that bug report the same workaround of using -Djava.net.preferIPv4Stack=true resolves this issue.
JBoss JGroups began throwing a SocketException on java.net.MulticastSocket.setInterface when we upgraded from 7u67 to 7u71 (64 bit JRE). Confirmed problem is repeatable on 7u72 as well. Looking at the JGroups code I was able to repeat the problem with a simple sample program pasted below. After compiling this I can call it passing my systems public IP address as an argument and it runs fine on 7u65 or 7u67 but when I use 7u71 or 7u72 to run it I get the exception. Searching for a bug I found the one listed above that was resolved some time ago but as mentioned above the same workaround works. When I use the preferIPv4Stack=true property it runs fine on all versions.
Sample application to reproduce issue:
---------------------------------------------------------
import java.net.*;
public class Socket
{
public static void main(String[] args)
{
try
{
String bind_ip = args[0];
System.out.println("Getting socket on: "+bind_ip+"\n");
InetAddress bind_addr = InetAddress.getByName(bind_ip);
int mcast_port = 35000;
MulticastSocket mcast_sock = new MulticastSocket(mcast_port);
mcast_sock.setInterface(bind_addr);
}
catch (Exception e)
{
System.out.println("Exception: "+e+"\n");
}
}
}
----------------------------------------------
Full stack trace:
java.net.SocketException: An invalid argument was supplied
at java.net.TwoStacksPlainDatagramSocketImpl.socketNativeSetOption(Native Method)
at java.net.TwoStacksPlainDatagramSocketImpl.socketSetOption(TwoStacksPlainDatagramSocketImpl.java:145)
at java.net.AbstractPlainDatagramSocketImpl.setOption(AbstractPlainDatagramSocketImpl.java:310)
at java.net.MulticastSocket.setInterface(MulticastSocket.java:467)
at Socket.main(Socket.java:14)
REGRESSION. Last worked in version 7u67
ADDITIONAL REGRESSION INFORMATION:
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the following sample application and pass the systems public IP address on a Windows Server 2008 R2 or Windows 7 64-bit system with IPv6 disabled (un-checked) on the public adapter. You can't use localhost, it will work fine.
import java.net.*;
public class Socket
{
public static void main(String[] args)
{
try
{
String bind_ip = args[0];
System.out.println("Getting socket on: "+bind_ip+"\n");
InetAddress bind_addr = InetAddress.getByName(bind_ip);
int mcast_port = 35000;
MulticastSocket mcast_sock = new MulticastSocket(mcast_port);
mcast_sock.setInterface(bind_addr);
}
catch (Exception e)
{
System.out.println("Exception: "+e+"\n");
}
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception thrown by the setInterface method. Sample application should return with no error.
ACTUAL -
The following stack trace is thrown:
java.net.SocketException: An invalid argument was supplied
at java.net.TwoStacksPlainDatagramSocketImpl.socketNativeSetOption(Native Method)
at java.net.TwoStacksPlainDatagramSocketImpl.socketSetOption(TwoStacksPlainDatagramSocketImpl.java:145)
at java.net.AbstractPlainDatagramSocketImpl.setOption(AbstractPlainDatagramSocketImpl.java:310)
at java.net.MulticastSocket.setInterface(MulticastSocket.java:467)
at Socket.main(Socket.java:14)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.net.SocketException: An invalid argument was supplied
at java.net.TwoStacksPlainDatagramSocketImpl.socketNativeSetOption(Native Method)
at java.net.TwoStacksPlainDatagramSocketImpl.socketSetOption(TwoStacksPlainDatagramSocketImpl.java:145)
at java.net.AbstractPlainDatagramSocketImpl.setOption(AbstractPlainDatagramSocketImpl.java:310)
at java.net.MulticastSocket.setInterface(MulticastSocket.java:467)
at Socket.main(Socket.java:14)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Use the following sample application and pass the systems public IP address on a Windows Server 2008 R2 or Windows 7 64-bit system with IPv6 disabled (un-checked) on the public adapter. You can't use localhost, it will work fine.
import java.net.*;
public class Socket
{
public static void main(String[] args)
{
try
{
String bind_ip = args[0];
System.out.println("Getting socket on: "+bind_ip+"\n");
InetAddress bind_addr = InetAddress.getByName(bind_ip);
int mcast_port = 35000;
MulticastSocket mcast_sock = new MulticastSocket(mcast_port);
mcast_sock.setInterface(bind_addr);
}
catch (Exception e)
{
System.out.println("Exception: "+e+"\n");
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use -Djava.net.preferIPv4Stack=true