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