[SNMP4J] Null Pointer Exception in DefaultTcpTransportMapping.close()

Frank Fock fock at agentpp.com
Thu Aug 17 21:23:33 CEST 2006


Hi,

SNMP4J v1.7.4 can now be downloaded from http://www.snmp4j.org.
This version should fix the below described problem.
Please let me know if you still encounter problems anyway!

Best regards,
Frank

Frank Fock wrote:
> I expect the fix to be available later today.
> I will post it here when it has been uploaded.
> 
> Best regards,
> Frank
> 
> Prusi, Jesse R wrote:
>> Thanks for the response Frank.  Do you have an estimate on when you will
>> have the fix tested?  Can you please provide a patch when you have it
>> ready so I won't have to wait for the next release?
>>
>> Thanks,
>> Jesse
>>
>> -----Original Message-----
>> From: Frank Fock [mailto:fock at agentpp.com] Sent: Wednesday, August 16, 
>> 2006 12:20 AM
>> To: Prusi, Jesse R
>> Cc: snmp4j at agentpp.org
>> Subject: Re: [SNMP4J] Null Pointer Exception in
>> DefaultTcpTransportMapping.close()
>>
>> Hi Jesse,
>>
>> I am working on this. My current approach synchronizes
>> the access to the "server" member. I have to test if
>> it works now...
>>
>> Best regards,
>> Frank
>>
>> Prusi, Jesse R wrote:
>>> Upon further investigation this fix did not solve the problem.  The
>>> sockets are still not getting closed.  Any ideas?
>>>
>>> Thanks,
>>> Jesse
>>>
>>> -----Original Message-----
>>> From: snmp4j-bounces at agentpp.org [mailto:snmp4j-bounces at agentpp.org]
>> On
>>> Behalf Of Prusi, Jesse R
>>> Sent: Tuesday, August 15, 2006 7:27 AM
>>> To: snmp4j at agentpp.org
>>> Subject: RE: [SNMP4J] Null Pointer Exception in
>>> DefaultTcpTransportMapping.close()
>>>
>>> I updated the close() method to catch the NPE when join() is called
>> and
>>> the server thread has already been set to null because run() exited.
>>> This allows the sockets to be closed so the ports are freed up and it
>>> seems to fix the problem.  Anyone else have a better solution?
>>>
>>>
>>>   /**
>>>    * Closes all open sockets and stops the internal server thread that
>>>    * processes messages.
>>>    */
>>>   public synchronized void close() {
>>>     if (server != null) {
>>>       server.close();
>>>       try {
>>>         server.join();
>>>       }
>>>       catch (NullPointerException npe) {
>>>         logger.warn(npe);
>>>       }
>>>       catch (InterruptedException ex) {
>>>         logger.warn(ex);
>>>       }
>>>       server = null;
>>>       for (Iterator it = sockets.values().iterator(); it.hasNext(); )
>> {
>>>         SocketEntry entry = (SocketEntry)it.next();
>>>         try {
>>>           synchronized (entry) {
>>>              entry.getSocket().close();
>>>           }
>>>           logger.debug("Socket to "+entry.getPeerAddress()+" closed");
>>>         }
>>>         catch (IOException iox) {
>>>           // ingore
>>>           logger.debug(iox);
>>>         }
>>>       }
>>>       if (socketCleaner != null) {
>>>         socketCleaner.cancel();
>>>       }
>>>       socketCleaner = null;
>>>     }
>>>   }
>>>
>>> Thanks,
>>> Jesse
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: snmp4j-bounces at agentpp.org [mailto:snmp4j-bounces at agentpp.org]
>> On
>>> Behalf Of Prusi, Jesse R
>>> Sent: Monday, August 14, 2006 6:44 PM
>>> To: snmp4j at agentpp.org
>>> Subject: [SNMP4J] Null Pointer Exception in
>>> DefaultTcpTransportMapping.close()
>>>
>>> Hello,
>>>
>>> I'm using SNMP4J 1.7.3 on a Windows XP machine.
>>>
>>> I find a get a Null Pointer Exception when snmp.close().  Here is my
>>> sample code:
>>>
>>> public class SnmpTest {
>>>
>>>     public static void main(String[] args) {
>>>         try{
>>>             DefaultTcpTransportMapping myTransport = new
>>> DefaultTcpTransportMapping(
>>>                     new
>>> TcpAddress(InetAddress.getLocalHost(),
>>>                             10163));
>>>             myTransport.setMaxInboundMessageSize(1400);
>>>             myTransport.setConnectionTimeout(1000);
>>>            
>>>             Snmp snmp = new Snmp(myTransport);
>>>             OctetString localEngineId = new
>>> OctetString(MPv3.createLocalEngineID());
>>>             USM usm = new
>>> USM(SecurityProtocols.getInstance(), localEngineId, 0);
>>>     
>>> SecurityModels.getInstance().addSecurityModel(usm);
>>>             snmp.listen();
>>>             System.out.println("Listening on port 10163");
>>>             for(int i=0; i < 10000; i++){
>>>                 System.out.println("spinning " + i);
>>>             }
>>>             snmp.close();
>>>             System.out.println("Closed Snmp Session");
>>>         }
>>>         catch(Exception e){
>>>             e.printStackTrace();
>>>         }
>>>     }
>>> }
>>>
>>> I get the following stack trace:
>>>
>>> java.lang.NullPointerException
>>>     at
>>>
>> org.snmp4j.transport.DefaultTcpTransportMapping.close(DefaultTcpTranspor
>>> tMapping.java:186)
>>>     at org.snmp4j.Snmp.close(Snmp.java:429)
>>>     at SnmpTest.main(SnmpTest.java:31)
>>>
>>> The NPE does not occur if I comment out the spinning for loop.  I
>>> thought this might have something to do with the timeout setting of
>> the
>>> TCP transport mapping, but I still get the error after increasing the
>>> timeout to 10000.  Any ideas why this is occurring?  Am I using the
>> TCP
>>> transport mapping incorrectly?
>>>
>>> Thanks, 
>>> Jesse Prusi
>>>
>>> _______________________________________________
>>> SNMP4J mailing list
>>> SNMP4J at agentpp.org
>>> http://lists.agentpp.org/mailman/listinfo/snmp4j
>>>
>>>
>>> _______________________________________________
>>> SNMP4J mailing list
>>> SNMP4J at agentpp.org
>>> http://lists.agentpp.org/mailman/listinfo/snmp4j
>>>
>>>
>>> _______________________________________________
>>> SNMP4J mailing list
>>> SNMP4J at agentpp.org
>>> http://lists.agentpp.org/mailman/listinfo/snmp4j
>>
> 

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list