[SNMP4J] NullPointerException at org.snmp4j.transport.DefaultUdpTransportMapping$ListenThread.run
Adam
adaslaw at gmail.com
Thu Jun 25 05:34:28 CEST 2009
Hello
I got a NullPointerException exception:
// Exception in thread "DefaultUDPTransportMapping_192.168.0.4/0"
java.lang.NullPointerException
// at
org.snmp4j.transport.DefaultUdpTransportMapping$ListenThread.run(Unknown
Source)
// at java.lang.Thread.run(Thread.java:619)
It's easy to reproduce:
1. Go to file: \snmp4j\src\org\snmp4j\tools\console\SnmpRequest.java
2. Rename main method to main2.
3. Create new main method:
public static void main(String[] args) throws InterruptedException
{
for(int i = 0; i < 100; i++)
{
main2(args);
System.out.println("i:" + i);
}
}
You will see (on Console or Debug view in Eclipse) that many threads are
slapped by NullPointerException.
I went into details and I can see that there is a synchronization problem in
DefaultUdpTransportMapping class. The problem is when
DefaultUdpTransportMapping.close() is called *before* ListenThread.run is
called.
In this case we will get NullPointerException in line:
socket.setSoTimeout(getSocketTimeout());
... because socket will be null (because was nullizied in close method a
moment before).
I created a fast fix to get over this synchronization problem. Path is not a
beauty piece of code, but this is simple workaround over this problem.
I someone is interested in my fix, see:
http://www.pasteyourcode.com/218
Hint: have a look at new mutex added to this class.
Regards,
AdamFromPoland
More information about the SNMP4J
mailing list