[SNMP4J] NullPointerException with snmp4j (Race condition bug?)

Frank Fock fock at agentpp.com
Thu Nov 3 22:45:23 CET 2011


Hi,

Creating and closing a Snmp instance to send a single
PDU is not recommended usage.
Nevertheless, it should not cause a NullPointerException
when used with a synchronous send method.
I will analyse it and fix it if necessary.

Best regards,
Frank


Am 03.11.2011 22:37, schrieb Appu Goundan:
> 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
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j




More information about the SNMP4J mailing list