Bug 155186 - java/openjdk7: False exception throw by NetworkInterface.isUp() (and probably others)
Summary: java/openjdk7: False exception throw by NetworkInterface.isUp() (and probably...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Greg Lewis
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-02 11:40 UTC by Alex Hayward
Modified: 2011-07-08 08:30 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Hayward 2011-03-02 11:40:11 UTC
NetworkInterface.isUp() can throw a SocketException when there was in
fact no error. This breaks, for example, JGroups.

getFlags in
/usr/ports/java/openjdk7/work/openjdk/jdk/src/solaris/native/java/net/NetworkInterface.c
returns if2.ifr_flags where if2 is a struct ifreq. Callers expect a
negative (int) result on error, a positive one otherwise. ifr_flags is
a short and the top bit can be set of multi-cast capable interfaces.
This remains negative when cast to an int and the caller believes an
error occurred. An exception is thrown based on whatever errno happens
to be.

My JDK port version is openjdk-7.0.122

Fix: 

Change the last statement of getFlags to 'return ((int) if2.ifr_flags) & 0xffff;'
How-To-Repeat: Run this (from JGroups):

import java.net.*;
import java.util.*;

public class test {
    public static void main(String[] argv) throws SocketException {
        InetAddress address=null ;

        try {
            Enumeration intfs=NetworkInterface.getNetworkInterfaces();
            while(intfs.hasMoreElements()) {
                NetworkInterface intf=(NetworkInterface)intfs.nextElement();
                if(intf.isUp()) {
                    //address=getAddress(intf, AddressScope.NON_LOOPBACK) ;
                    //System.err.println(address);
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
}
Comment 1 Alex Hayward 2011-03-02 12:43:04 UTC
Ooops, this was meant to be in the 'java' category. Sorry if that's not 
obvious.

  Alex
Comment 2 Bruce Cran freebsd_committer freebsd_triage 2011-03-02 12:51:29 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-ports-bugs

Ports PR (java).
Comment 3 Edwin Groothuis freebsd_committer freebsd_triage 2011-03-02 12:52:35 UTC
Responsible Changed
From-To: freebsd-ports-bugs->glewis

Over to maintainer (via the GNATS Auto Assign Tool)
Comment 4 dfilter service freebsd_committer freebsd_triage 2011-07-08 08:28:59 UTC
glewis      2011-07-08 07:28:46 UTC

  FreeBSD ports repository

  Modified files:
    java/openjdk7        Makefile 
  Added files:
    java/openjdk7/files  
                         patch-src-solaris-native-java-net-NetworkInterface.c 
  Log:
  . Try harder to make sure the flags returned from getFlags isn't negative,
    since a number of places in the code check for that and assume that it
    means an error occurred.  On FreeBSD, in particular, the value of
    ifr_flags can be negative if multicast is enabled on the socket since
    the possible flags have expanded to fill more than a short.
  
    Instead of blindly promoting ifr_flags to an int, which will preserve
    the sign, we fill the int return value with ifr_flagshigh in the high
    16 bits and ifr_flags in the low 16 bits.
  
  PR:             155186
  Reported by:    Alex Hayward <xelah-freebsd-pr@xelah.com>
  
  Revision  Changes    Path
  1.29      +1 -0      ports/java/openjdk7/Makefile
  1.1       +17 -0     ports/java/openjdk7/files/patch-src-solaris-native-java-net-NetworkInterface.c (new)
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 5 Greg Lewis freebsd_committer freebsd_triage 2011-07-08 08:29:17 UTC
State Changed
From-To: open->closed

Thanks for the report.  I used a different fix for FreeBSD, but I think your 
change applies well for other BSD variants.