[SNMP4J] issue with OctetString.isPrintable
Miller, Mark
Mark.Miller at netapp.com
Fri Apr 1 17:08:41 CEST 2011
We have uncovered an issue with OctetString.isPrintable(). For the
OctetString for 1C:32:41:1C:4E:38 iisPrintable is returning true but 1C
is not a printable character it is the File Seperator character. I
think the issue is that OctetString.isPrintable assumes that all white
space characters are printable but 1C is a whitespace character
according to the Java Character class but it is not printable.
I have written a short program to demonstrate:
import org.snmp4j.smi.OctetString;
public class OctetStringPrintableTest {
public static void main(String[] args) {
String hexString = "1C:32:41:1C:4E:38";
OctetString octetString = OctetString.fromHexString(hexString);
if (octetString.isPrintable()) {
System.out.println(String.format("HexString %s is printable
as an octetString %s", hexString, octetString.toString()));
} else {
System.out.println(String.format("HexString %s is not
printable as an octetString", hexString));
}
byte firstByte = octetString.get(0);
char firstChar = (char)firstByte;
if (Character.isISOControl(firstChar)) {
System.out.println("1C isISOControl");
} else {
System.out.println("1C not isISOControl");
}
if (Character.isWhitespace(firstChar)) {
System.out.println("1C isWhitespace");
} else {
System.out.println("1C not isWhitespace");
}
}
}
The output is:
HexString 1C:32:41:1C:4E:38 is printable as an octetString
2A
N8
1C isISOControl
1C isWhitespace
Thanks in advance,
Mark
More information about the SNMP4J
mailing list