OpenAF/openaf

SNMP trap number value cast exception

Closed this issue · 0 comments

Description
Whenever sending a SNMP trap with an object of type "integer" there are cases where the following exception can occur:

Error while executing operation: Wrapped java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer

How to reproduce
Just try to send a number 1 or number 5, for example:

function sendTrap(aSNMPObject, aOID, anEntry) {
   aSNMPObject.trap(aOID, [
     { OID: anEntry.oid, type: anEntry.type, value: anEntry.value }
  ], false);
}

var myValue = 5;
sendTrap({ OID: myOID, type: "i", value: myValue })  // No exception
myValue = 1
sendTrap({ OID: myOID, type: "i", value: myValue })  // Exception might occur

Expected behavior
With either value 1 or 5 the javascript to java conversion should work but it seems a Rhino issue. Or, at least, the sendTrap function should cast from Double to Integer if needed internally.

Workaround
Using the "How to reproduce" code above just force the java type conversion:

sendTrap({ OID: myOID, type: "i", value: java.lang.Integer.valueOf(myValue) })