NPE in LookupDiscovery when list of interfaces has null entry
Gregg Wonderly <[email protected]> Tue, 22 Apr 2008 13:06:23 -0500
| Newsgroups | gmane.comp.java.sun.jini |
|---|---|
| Message-ID | <[email protected]> |
I recently swapped harddrives between two identical machines to see if that
would expose an suspected problem with one of the drives. These are linux
machines, and the /etc/sysconfig/network-scripts/ifcfg-eth0 files had MAC
addresses in them. Linux (Fedora-8) noted that these MAC addresses didn't jive
with what it could see on the machine the drives were swapped to, and the
interfaces came up as eth1 instead. I had a set of discovery interfaces
specified in the config using
multicastInterfaces = new java.net.NetworkInterface[] {
java.net.NetworkInterface.getByName("lo"),
java.net.NetworkInterface.getByName("eth0")
};
This caused a null pointer to be in the array, which created some issues with
the nics[i].getName() references in AnnouncementListener constructor, near line
1030. I've made logging changes and other things in my copy of this class, so
here is the associated code showing the conditional check I put into the loop.
Gregg Wonderly
--------------------------------
switch(nicsToUse) {
case NICS_USE_ALL:
/* Using all interfaces. Skip (but report) any interfaces
* that are "bad" or not configured for multicast.
*/
for(int i=0;i<nics.length;i++) {
if( nics[i] == null ) {
logger.warning("nic entry null at #"+i);
continue;
}
try {
sock.setNetworkInterface(nics[i]);
sock.joinGroup(Constants.getAnnouncementAddress());
} catch(IOException e) {
if(retryNics == null) {
retryNics = new ArrayList(nics.length);
}//endif
retryNics.add(nics[i]);
Logger logger =
Logger.getLogger(LookupDiscovery.class.getName()+".multicast"+"."+nics[i].getName());
if( logger.isLoggable(Levels.HANDLED) ) {
LogRecord logRec =
new LogRecord(Levels.HANDLED,
"a network interface "
+"is bad or not configured "
+"for multicast: {0}");
logRec.setParameters(new Object[]{nics[i]});
logRec.setLoggerName( logger.getName() );
logRec.setThrown(e);
logger.log(logRec);
}//endif
}
}//end loop
break;
case NICS_USE_LIST:
/* Using a configured list of specific interfaces. Skip
* (but report) any interfaces that are "bad" or not
* configured for multicast.
*/
for(int i=0;i<nics.length;i++) {
if( nics[i] == null ) {
logger.fine("nic entry null at #"+i);
continue;
}
try {
sock.setNetworkInterface(nics[i]);
sock.joinGroup(Constants.getAnnouncementAddress());
} catch(IOException e) {
if(retryNics == null) {
retryNics = new ArrayList(nics.length);
}//endif
retryNics.add(nics[i]);
Logger logger =
Logger.getLogger(LookupDiscovery.class.getName()+"."+nics[i].getName()+".multicast");
if( logger.isLoggable(Level.SEVERE) ) {
LogRecord logRec =
new LogRecord(Level.SEVERE,
"a network interface is bad or "
+"not configured for "
+"multicast: {0}");
logRec.setParameters(new Object[]{nics[i]});
logRec.setThrown(e);
logRec.setLoggerName( logger.getName() );
logger.log(logRec);
}//endif
}
}//end loop
break;
--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to [email protected]