[SNMP4J] NullPointerException with snmp4j (Race condition bug?)
Appu Goundan
asgoundan at yahoo.com
Thu Nov 3 22:37:10 CET 2011
Hello,
Sorry if you're getting this twice, I got an email the first time saying I'm not allowed to post. I thought I had signed up but apparently did not.
I'm using the 2.0.2 version of snmp-4j
I think a race condition exists in DefaultUdpTransportMapping() that leads to a NullPointerException:
Here is the scenario :
TransportMapping transport = new DefaultUdpTransportMapping();
transport.listen();
/*
* set up all the pdu and target stuff here
*/
Snmp snmp = new Snmp(transport);
snmp.send(pdu, cTarget);
snmp.close();
Here is the exception that gets generated (on occassion)
Exception in thread "DefaultUDPTransportMapping_127.0.0.1/0" java.lang.NullPointerException
at org.snmp4j.transport.DefaultUdpTransportMapping$ListenThread.run(DefaultUdpTransportMapping.java:321)
at java.lang.Thread.run(Thread.java:662)
Now, the reason I think this is a race condition is because it only happens occassionally when running my test.
After looking through the code this is what I think is happening:
- snmp.close() is calling the transport.close() which sets socket = null;
-this
happens before transport.listen() can start it's listening thread, but
after it ensures the socket, so line 321 : socket.setSoTimeout(....) has
a null socket object?
Or am I just not using snmp4j correctly?
Thanks
More information about the SNMP4J
mailing list