Bug in Java 5 Integer.parseInt (stringValue, radix) ?
807591Jun 11 2008 — edited Jun 11 2008I think I've found a bug in Integer.parseInt (String, int). I have a method that takes a long value and needs to split it into two ints - one for the high-order bits and one for the low-order bits. The following code generates a NumberFormatException:
public void setIntValues (long createBits) {
String createHex = Long.toHexString (createBits);
System.out.println ("Create Hex: " + createHex);
String highHex = createHex.substring (0, 8);
String lowHex = createHex.substring (8);
System.out.println ("High Hex: " + highHex);
System.out.println ("Low Hex: " + lowHex);
setHighOrderBits (Integer.parseInt (highHex, 16));
setLowOrderBits (Integer.parseInt (lowHex, 16));
}
The calls to substring() do the right thing and split the 16-hex-char value into two 8-hex-char values that should then be parsed by Integer.parseInt (String, int). Sample output is:
Create Hex: 8c34c6ba0a31a444
High Hex: 8c34c6ba
Low Hex: 0a31a444
Suggestions? Is this fixed in Java 6?
Edited by: FlyingEagle on Jun 11, 2008 9:23 AM