[SNMP4J] SNMP.java bug?: Call to ResponseEvent constructor with org.snmp4j.Snmp$ReportProcessor as first argument resulting in ClassCastException (Snmp.java:1363)

Omair-Inam Abdul-Matin omairkhawaja at gmail.com
Tue Aug 10 22:38:04 CEST 2010


I have an application using SNMP4J with a custom responselistener.  On
occasion I get an exception with the following stack trace:


java.lang.ClassCastException: org.snmp4j.Snmp$ReportProcessor cannot
be cast to org.snmp4j.Snmp
 	at com.quest.monitoring.snmp.AbstractResponseListener.onResponse(AbstractResponseListener.java:43)
	at org.snmp4j.Snmp$ReportProcessor.processReport(Snmp.java:1363)
	at org.snmp4j.Snmp.processPdu(Snmp.java:1278)
	at org.snmp4j.MessageDispatcherImpl.fireProcessPdu(MessageDispatcherImpl.java:616)
	at org.snmp4j.MessageDispatcherImpl.dispatchMessage(MessageDispatcherImpl.java:287)
 	at org.snmp4j.MessageDispatcherImpl.processMessage(MessageDispatcherImpl.java:347)
	at com.quest.monitoring.snmp.ThreadPoolMessageDispatcher$MessageTask.run(ThreadPoolMessageDispatcher.java:186)
 	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
 	at java.lang.Thread.run(Unknown Source)

The code resulting in this exception is sample code in the Snmp javadocs:

((Snmp)event.getSource()).cancel(event.getRequest(), this);


I've looked at the Snmp.java class and found the following call:

reqListener.onResponse(new ResponseEvent(this,
              e.getPeerAddress(),
              reqPDU,
              pdu,
              reqUserObject));

which is located inside org.snmp4j.Snmp$ReportProcessor and that is why the
ClassCastException. Please correct me if I'm wrong, but it looks like the
code needs to be changed... so that all calls to new ResponseEvent in
Snmp.java pass in the Snmp instance as the first constructor argument,
instead of the inner ReportProcessor instance, as is being done in this
case.

Omair



More information about the SNMP4J mailing list