JDK-5051227 : Long.parseLong & Integer.parseInt Fails to Parse toHexString() output.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8,solaris_10
  • CPU: sparc
  • Submitted: 2004-05-21
  • Updated: 2004-06-02
  • Resolved: 2004-06-02
Related Reports
Duplicate :  
Relates :  
Description
see comments.

Comments
SUGGESTED FIX replace Integer.parseInt() method contents with: public static int parseInt(String a, int rad) { int len = a.length(); int mid = Long.valueOf(0x0ffffffffL, if (len > 4) { return (int)( ((Integer.parseInt(a.substring(0,(len - 4)),rad) & 0x0ffff) << 16) | ( Integer.parseInt(a.substring((len - 4),len),rad) & 0x0ffff ) ); } else { // Existing code... } } replace Long.parseLong() method contents with: public static long parseLong(String a, int rad) { int len = a.length(); if (len > 8) { return (long)( ((Long.parseLong(a.substring(0,(len - 8)),rad) & 0x0ffffffffL) << 32) | ( Long.parseLong(a.substring((len - 8),len),rad) & 0x0ffffffffL ) ); } else { // Existing code... } }
11-06-2004

EVALUATION The methods are behaving as specified; from toHexString: "Returns a string representation of the integer argument as an *unsigned* integer in base 16." from parseInt "Parses the string argument as a *signed* integer in the radix specified by the second argument." Therefore, negative hex values printed out with toHexString cannot be read back in with parseInt. However, this is an annoying inconsistency in the api; closing this bug as a dup of 4215269. ###@###.### 2004-06-01
01-06-2004