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(); } } }
Ooops, this was meant to be in the 'java' category. Sorry if that's not obvious. Alex
Responsible Changed From-To: freebsd-bugs->freebsd-ports-bugs Ports PR (java).
Responsible Changed From-To: freebsd-ports-bugs->glewis Over to maintainer (via the GNATS Auto Assign Tool)
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"
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.