Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Bug in Java 5 Integer.parseInt (stringValue, radix) ?

807591Jun 11 2008 — edited Jun 11 2008
I 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 9 2008
Added on Jun 11 2008
8 comments
1,376 views