[SNMP4J] TableUtils.getTable() null pointer exception

Stuart Johnston sgjohnston at gmail.com
Wed Apr 12 18:19:55 CEST 2017


Using TableUtils.getTable() can cause a null pointer exception when used with SNMPv3, when the PDU is created. DefaultPDUFactory.createPDU() is called, which calls 
applyContextInfoToScopedPDU() to set the engine ID. If the engine ID has not previously been set in the DefaultPDUFactory, then an NPE will be thrown. In fact, we really don’t want to have to specify the engine ID in the PDU factory, since snmp4j will automatically discover it and apply it if it isn’t set. The solution is to create a DefaultPDUFactory with an empty (rather than null) engine ID. In this cause, everything works as expected.

The immediate workaround is to call new DefaultPDUFactory(PDU.GET) rather than new DefaultPDUFactory(). new DefaultPDUFactory(PDU.GET) will create an empty, rather than null engine ID. I think the correct, long term fix is to change the constructor to:

/**
  * Creates a PDU factory for the {@link PDU#GET} PDU type.
  */
 public DefaultPDUFactory() {
     this(PDU.GET);
 }


More information about the SNMP4J mailing list