JDK-8179313 : Support of underscore symbol in valueOf and parseXXX methods.
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 8,9
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2017-04-25
  • Updated: 2017-04-26
  • Resolved: 2017-04-26
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
1.8.0._131

ADDITIONAL OS VERSION INFORMATION :
windows 7 professional 64

A DESCRIPTION OF THE PROBLEM :
input: 
public static void main(String[] args) {
       System.out.println(Integer.valueOf("1_000"));
    }
output:
Exception in thread "main" java.lang.NumberFormatException: For input string: "1_000"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:580)
	at java.lang.Integer.valueOf(Integer.java:766)
	at com.company.Main.main(Main.java:8)

Process finished with exit code 1


REGRESSION.  Last worked in version 8u131

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
execute code:
public class Main {
    //static
    public static void main(String[] args) {
        System.out.println(Integer.valueOf("1_000"));
    }
}

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
1000 in console output
ACTUAL -
Exception in thread "main" java.lang.NumberFormatException: For input string: "1_000"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:580)
	at java.lang.Integer.valueOf(Integer.java:766)
	at com.company.Main.main(Main.java:8)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NumberFormatException: For input string: "1_000"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:580)
	at java.lang.Integer.valueOf(Integer.java:766)
	at com.company.Main.main(Main.java:8)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

public class Main {
    //static
    public static void main(String[] args) {
        System.out.println(Integer.valueOf("1_000"));
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
It is dont looks like fully support of "_" symbol,
you need modify Integer class (public static int parseInt) to remove underline symbol before parsing. 

Its seems like you just forgot about this.

F.E: we store our number in config file, and is it like 1_000_000. and we need to write extra code to use it (if we reading string from config). 


Comments
Closing as a duplicate of JDK-6863378.
26-04-2017