JDK-8062249 : java.net.MulticastSocket.setInterface throws SocketException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7u72
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2008
  • CPU: x86
  • Submitted: 2014-10-24
  • Updated: 2014-11-24
  • Resolved: 2014-11-04
Related Reports
Duplicate :  
Relates :  
Description
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


Comments
Going to close as duplicate of JDK-6458027
04-11-2014

tested a current build of jdk7-dev with the sample and reproduced the problem. applying the fix from JDK-6458027 and the problem appears to be fixed. If 6458027 is back ported to jdk7 it should fix this problem. It was remiss of me to not have backported when fixing the issue in jdk8
01-11-2014

Customer confirmed that this issue is not reproducible on 8u20, 8u25, and 8u40. As of now this is only reproducible in 7u72. Moving ahead for further evaluation.
28-10-2014