After a while SNMP4J throws an exception

Hi,

I am using a 2.x version of the SNMP4J library to send messages to a SNMP server.
My problem is that after a period of time, about 2 months or so, the SNMP stops working throwing the following exception IllegalArgumentException “Argument must be an unsigned 32bit value”

I’ve looked through the code to see where this is thrown and found that UnsignedInteger32 class of the library, the method that throws this exception is setValue

  public void setValue(long value) {
    if ((value < 0) || (value > 4294967295L)) {
      throw new IllegalArgumentException(
          "Argument must be an unsigned 32bit value");
    }
    this.value = value;
  }

This is called by the setTimestamp in the PDUv1 class

public void setTimestamp(long timeStamp) {
    checkV1TRAP();
    this.timestamp.setValue(timeStamp);
  }

which is called by our code when we try to build the PDU as follows:
case SNMP_V1:
OID specOID = new OID (mibTableEntry.oidValue);
int specificTrap = specOID.removeLast ();
((PDUv1) pdu).setTimestamp (sysUpTimeImplInstance.get ().toMilliseconds ());
((PDUv1) pdu).setEnterprise (specOID);
((PDUv1) pdu).setSpecificTrap (specificTrap);
break;

where sysUpTimeImplInstance is the following instance:
private final static SNMPv2MIB.SysUpTimeImpl sysUpTimeImplInstance = new SNMPv2MIB.SysUpTimeImpl ();

Setting the instance to final static was done to respect the SNMP RFC.

Why question is why does the timestamp value limited to 4294967295L since from what I can tell UnsignedInteger32 seems like a wrapper for the long primitive.

Does something happen when that value is exceeded?

Thanks

The error is in sysUptimeImplInstance.get().toMilliseconds()
Replace the bold part by getValue()

sysUptimeImplInstance.get().getValue()

and it will work. SysUptime is measured in 1/100 seconds - not milliseconds.

The overflow is happening because UnsignedInteger32 is an unsigned 32bit integer value on the wire defined by the SNMP protocol.