JDK-8065575 : MulticastSocket Exception on non-default ethernet port/ new to 7.71
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7u71,7u72
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-11-07
  • Updated: 2014-12-03
  • Resolved: 2014-12-03
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
Java 7u71 32 bit

C:\Program Files (x86)\Java\jdk1.7.0_71\bin>java.exe -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Netbeans 8.0.1
2 ethernet ports, 1 virtual ethernet port
Broadcom NetExtreme Gigabit Ethernet
Realtek PCI GBE Family Controller
VirtualBox Host-Only Ethernet Adapter

A DESCRIPTION OF THE PROBLEM :
When I attempt to open an inbound multicast port on an interface other than the default, the system exceptions claiming an invalid input.  This is new to 7u71

REGRESSION.  Last worked in version 7u67

ADDITIONAL REGRESSION INFORMATION: 
C:\Program Files (x86)\Java\jdk1.7.0_67\bin>java.exe -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) Client VM (build 24.65-b04, mixed mode, sharing)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to open a multicast port on an interface other than the first one on a machine (this will require a box with at least 2 Ethernet ports).  See the code example for how I am doing it.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Will open the port on my manager and allow me to begin listening for traffic on my network.
ACTUAL -
Exception is generated when I set the interface on the multicast object: An invalid argument was supplied

ERROR MESSAGES/STACK TRACES THAT OCCUR :
run:
Exception in thread "main" 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 javaapplication1.SelectForm.openBroadcastPort(SelectForm.java:68)
	at javaapplication1.SelectForm.main(SelectForm.java:123)
Java Result: 1



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package javaapplication1;

import java.awt.Component;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.InterfaceAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.swing.JOptionPane;

public class SelectForm extends javax.swing.JPanel {
    
    private ServerSocket ssock;
    private MulticastSocket socket;
    
    public SelectForm() {
        initComponents();
    }

    public List<InetAddress> getActiveIp4Address() {
        List<InetAddress> addresses = new ArrayList<>();
        try {
            Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
            while (nis.hasMoreElements()) {
                NetworkInterface ni = nis.nextElement();
                if (ni.isUp() && !ni.isVirtual() && !ni.isLoopback()) {
                    for (InterfaceAddress ia : ni.getInterfaceAddresses()) {
                        InetAddress inetAddress = ia.getAddress();
                        
                        if (inetAddress instanceof Inet4Address && !inetAddress.toString().startsWith("/169.")) {
                            addresses.add(inetAddress);
                        }
                    }
                }
            }
            return addresses;
        } catch (RuntimeException e) {
            throw e;
        } catch (SocketException e) {
            throw new RuntimeException(e);
        }
    }
    
    private InetAddress selectAnInterface(Component parentComponent, List<InetAddress> addresses) {
        return (InetAddress) JOptionPane.showInputDialog(parentComponent,
                "Please Select the interface to attach to",
                "Multiple Interfaces Detected",
                JOptionPane.INFORMATION_MESSAGE, 
                null,
                addresses.toArray(),
                addresses.get(0));
    }
    
    private void openBroadcastPort(InetSocketAddress nodeAddress, InetSocketAddress broadcastAddress,
            int broadcastport, NetworkInterface networkInterface) throws IOException {

            ssock = new ServerSocket(nodeAddress.getPort());
            
            socket = new MulticastSocket(broadcastport);

            socket.setInterface(nodeAddress.getAddress());
            
            socket.joinGroup(broadcastAddress,networkInterface);
            
            socket.setReuseAddress(true);
            
        
            
    }
    
    public NetworkInterface getInterfaceForIpAddress(InetAddress address) {
        try {
            NetworkInterface ni = NetworkInterface.getByInetAddress(address);
            if (ni == null) {
                throw new IllegalStateException("No network interface found for address " + address);
            }
            return ni;
        } catch (SocketException ex) {
            throw new RuntimeException(ex);
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        
        int directPort = 12345;
        int broadcastPort = 23456;
        String broadcastIP= "239.1.2.3";
        
        SelectForm form = new SelectForm();
        
        List<InetAddress> addresses = form.getActiveIp4Address();
        InetAddress active;
        
        if (addresses == null || addresses.size() < 1) {
            throw new IllegalStateException("No active network interfaces with IP 4 address on this machine");
        } else if (addresses.size() > 1) {
            active = form.selectAnInterface(form, addresses);
            
            //if we cancelled out, quit
            if (active == null) {
                throw new IllegalStateException("No network interface was selected, can not continue");
            }
        } else {
            active = addresses.get(0);
        }
        
        InetSocketAddress nodeAddress = new InetSocketAddress(active, directPort);
        InetSocketAddress broadcastAddress = new InetSocketAddress(
                    broadcastIP,
                    broadcastPort);
        NetworkInterface ethernet = form.getInterfaceForIpAddress(active);
        
        form.openBroadcastPort(nodeAddress, broadcastAddress, broadcastPort, ethernet);
       
        
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>                        


    // Variables declaration - do not modify                     
    // End of variables declaration                   
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
revert back to 7u67


Comments
dup of 6458027
03-12-2014

as the comments show this is resolved in the latest jdk7
24-11-2014

Pardeep, do you have systems set up where I could login and see the issue myself?
24-11-2014

Tested and reproduced successfully with JDK 7u71 and 7u72. Run fine with JDK 7u67, and 8u25, 8u40.
20-11-2014