[SNMP4J] Another race condition fix for DefaultUdpTransportMapping

Paul Marquis paul at viridity.com
Thu Sep 23 23:44:30 CEST 2010


Version 1.11.1 of SNMP4J included a fix for a race condition in  
DefautlUdpTrasnportMapping which caused a NullPointerException.   
However, there is still one that remains while attempting to read a  
packet and I see this from time to time.  Below is a patch that fixes  
the problem for me that I'd like to submit for review.

Index: src/org/snmp4j/transport/DefaultUdpTransportMapping.java
===================================================================
--- src/org/snmp4j/transport/DefaultUdpTransportMapping.java	(revision  
215)
+++ src/org/snmp4j/transport/DefaultUdpTransportMapping.java	(working  
copy)
@@ -337,7 +337,11 @@
                                                      
udpAddress.getPort());
          try {
            try {
-            socket.receive(packet);
+            DatagramSocket readingSocket = socket;
+            if (readingSocket == null) {
+              continue;
+            }
+            readingSocket.receive(packet);
            }
            catch (InterruptedIOException iiox) {
              if (iiox.bytesTransferred <= 0) {




More information about the SNMP4J mailing list