报错内容
java.io.IOException: Length greater than 32bit are not supported for integers: at position 1030
at org.snmp4j.asn1.BER.decodeInteger(BER.java:695)
at org.snmp4j.smi.Integer32.decodeBER(Integer32.java:60)
at org.snmp4j.smi.AbstractVariable.createFromBER(AbstractVariable.java:173)
at org.snmp4j.smi.VariableBinding.decodeBER(VariableBinding.java:191)
at org.snmp4j.PDU.decodeBER(PDU.java:584)
at org.snmp4j.mp.MPv2c.prepareDataElements(MPv2c.java:201)
查询到这个是snmp得bug
https://bugzilla.redhat.com/show_bug.cgi?id=654384
源码分析
AbstractVariable 内联代码片
。
int type = inputStream.read();
....
variable = createVariable(type);
private static Variable createVariable(int smiSyntax) {
switch (smiSyntax) {
case SMIConstants.SYNTAX_OBJECT_IDENTIFIER: {
return new OID();
}
case SMIConstants.SYNTAX_INTEGER: {
return new Integer32();
}
case SMIConstants.SYNTAX_OCTET_STRING: {
return new OctetString();
}
}
}
发现在获取int type = inputStream.read(); type为integer32类型,那么当返回数据超过2 (31)长度时,无法处理,并报出异常。
解决办法
使用Counter64()实体类解析integer32得内容,尝试已经可以使用,但需要注释掉类型判断部分。
public void decodeBER(BERInputStream inputStream) throws java.io.IOException {
BER.MutableByte type = new BER.MutableByte();
long newValue = BER.decodeUnsignedInt64(inputStream, type);
if (type.getValue() != BER.COUNTER64) {
throw new IOException("Wrong type encountered when decoding Counter64: " +
type.getValue());
}
setValue(newValue);
}
以上为个人建议,这是第一次写文章,如有错误请指正。