JDK-8282522 : Error in method setNetworkInterface of MulticastSocket class
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 17
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2022-02-28
  • Updated: 2022-03-07
  • Resolved: 2022-03-07
Related Reports
Duplicate :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
OS=Windows_NT
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=5e03

C:\Users\user>java -version
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
Error in method setNetworkInterface of MulticastSocket class when InetAddress is instance of Inet4Address, the error ocurrs when try set Net.setInterface6, in line 364 of DatagramChannelImpl class,  but the InetAddress is not a instance of Inet6Address.


---------- BEGIN SOURCE ----------
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

import java.io.IOException;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;

import org.junit.jupiter.api.Test;

class Test_MulticastSocket {

	@Test
	void test() {
		String sourceIP = "192.168.55.1";
		int pPort = 1418;
		MulticastSocket s = null;
		
		try {
			s = new MulticastSocket(pPort);
			InetAddress adrs = InetAddress.getByName(sourceIP);
			NetworkInterface ntwIn = NetworkInterface.getByInetAddress(adrs);
			s.setNetworkInterface(ntwIn);
			assertTrue(true);
			
		} catch (IOException e) {
			if (s != null) {
				s.close();
			}
			fail(e.getMessage());
		}
	}
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Based on the above input, closing as duplicate
07-03-2022

Response from the submitter: When I run with -Djava.net.preferIPv4Stack=true works it ok.
04-03-2022

Requested the submitter try above workaround.
04-03-2022

[~tongwan] Can you ask the submitter to run with -Djava.net.preferIPv4Stack=true to see if that works around the issue?
04-03-2022

More information from the submitter: IPV6 is disable and the exception is : Exception in thread "main" java.net.SocketException: Invalid argument: no further information at java.base/sun.nio.ch.Net.setInterface6(Native Method) at java.base/sun.nio.ch.DatagramChannelImpl.setOption(DatagramChannelImpl.java:364) at java.base/sun.nio.ch.DatagramSocketAdaptor.setOption(DatagramSocketAdaptor.java:420) at java.base/sun.nio.ch.DatagramSocketAdaptor.setNetworkInterface(DatagramSocketAdaptor.java:605) at java.base/java.net.MulticastSocket.setNetworkInterface(MulticastSocket.java:445) This happens in jdk 17.0.2
04-03-2022

Requested the submitter to provide the following information: What is the exception observed Is IPv6 disabled? Is it a dup of JDK-8272476?
03-03-2022

The original description didn't mention that they had disabled IPv6. If that is so then it does appear to be a dup of JDK-8272476. I have initial changes to fix that.
02-03-2022

I was able to reproduce this by disabling IPv6 on an interface, then assigning that interface to MulticastSocket. The exact exception was: Exception in thread "main" java.net.SocketException: Invalid argument: no further information at java.base/sun.nio.ch.Net.setInterface6(Native Method) at java.base/sun.nio.ch.DatagramChannelImpl.setOption(DatagramChannelImpl.java:364) at java.base/sun.nio.ch.DatagramSocketAdaptor.setOption(DatagramSocketAdaptor.java:420) at java.base/sun.nio.ch.DatagramSocketAdaptor.setNetworkInterface(DatagramSocketAdaptor.java:605) at java.base/java.net.MulticastSocket.setNetworkInterface(MulticastSocket.java:445) same exception in JDK19; works fine in 11. If it's the same exception, then this is a duplicate of JDK-8272476
02-03-2022

I have re-implementation of this code to deal with more cases where IPv4/IPv6 is enabled on some interfaces and not others. It would be useful to understand more about the issue here. What exception is the submitter seeing?
02-03-2022

The observations on Windows 10: JDK 17: Passed, no failed test observed.
02-03-2022