JDK-7104258 : Integer.parseInt("ffffffff", 16) fails
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2011-10-24
  • Updated: 2012-03-20
  • Resolved: 2011-10-24
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
1.7.0_147-icedtea if you use Long.parseLong

ADDITIONAL OS VERSION INFORMATION :
Linux knuffelchen 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
This bug encounters if you try to decode
Color.WHITE
code:
Color.decode("0x" + Color.White.getRgb()).

Integer.parseInt failed.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to run this statement:

Integer.parseInt("ffffffff", 16);

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
0xffffffff
ACTUAL -
java.lang.NumberFormatException: For input string: "ffffffff"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
@Test
public void testGetColour() {
        Color.decode("0x" + Integer.toHexString(Color.WHITE.getRGB()));
}

@Test
public void testParseInt() {
        Integer.parseInt(Integer.toHexString(0xffffffff), 16);
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Color decodeColor() {
  return new Color(Long.decode("ffffffff", 16).intValue(), true);
}

Comments
EVALUATION Integer.parseInt treats its input as signed rather than unsigned so ffffffff is out of range. Closing as a duplicate of 4215269.
24-10-2011