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

Frank Fock fock at agentpp.com
Tue Aug 10 23:12:42 CEST 2010


Hi,
The example code simplifies a bit, but the code is correct. If the  
code would have been changed, it will not be distinguishable if a  
ResponseEvent has been generated on behalf of a report processing or  
not.
Instead using the source object reference, use the Snmp reference  
directly (or via the user object).

Best regards,
Frank

Am 10.08.2010 um 22:38 schrieb Omair-Inam Abdul-Matin <omairkhawaja at gmail.com 
 >:

> 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
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j



More information about the SNMP4J mailing list