[SNMP4J] Null Pointer Exception in DefaultTcpTransportMapping.close()
Prusi, Jesse R
jesse.r.prusi at lmco.com
Tue Aug 15 03:44:15 CEST 2006
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
More information about the SNMP4J
mailing list