As you know, I've been working on the valueOf/parseDouble methods which turn
strings into floating-point values. The existing implementation allows
integer-only strings like "1234", which is against the spec. I've fixed this
bug; but fixing this seems to cause the compiler to crash on inputs like "140d",
that is, an integer string followed by a float type suffix ('f', 'F', 'd', or
'D').
Poking around briefly, I found the following comment in Scanner.java:
/**
* The value of a literal token, recorded as a string.
* For numbers, leading 0x and 'f', 'd', 'l' suffixes are suppressed.
*/
public String stringVal() {
return new String(sbuf, 0, sp);
}
which implies the scanner/parser is stripping off the trailing type suffix
before calling parseDouble. If that is the case, it is a bug in the compiler.
I've tested the my new code separately and it behaves properly on strings like
"140d"; i.e. it accepts them but rejects "140".
Stack trace output of failing build (after gmake clobber) attached below.
Thanks,
-Joe
An exception has occurred in the compiler (1.4.1-internal). Please file a bug at
the Java Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi) after
checking the Bug Parade for duplicates. Include your program and the following
diagnostic in your report. Thank you.
java.lang.NumberFormatException: For input string: "0"
at
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at
java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1244)
at java.lang.Float.valueOf(Float.java:210)
at com.sun.tools.javac.v8.parser.Parser.literal(Parser.java:345)
at com.sun.tools.javac.v8.parser.Parser.term3(Parser.java:811)
at com.sun.tools.javac.v8.parser.Parser.term2(Parser.java:525)
at com.sun.tools.javac.v8.parser.Parser.term1(Parser.java:494)
at com.sun.tools.javac.v8.parser.Parser.term(Parser.java:435)
at com.sun.tools.javac.v8.parser.Parser.termRest(Parser.java:450)
at com.sun.tools.javac.v8.parser.Parser.term(Parser.java:438)
at com.sun.tools.javac.v8.parser.Parser.termRest(Parser.java:450)
at com.sun.tools.javac.v8.parser.Parser.term(Parser.java:438)
at com.sun.tools.javac.v8.parser.Parser.termRest(Parser.java:450)
at com.sun.tools.javac.v8.parser.Parser.term(Parser.java:438)
at com.sun.tools.javac.v8.parser.Parser.termRest(Parser.java:450)
at com.sun.tools.javac.v8.parser.Parser.term(Parser.java:438)
at com.sun.tools.javac.v8.parser.Parser.term(Parser.java:418)
at
com.sun.tools.javac.v8.parser.Parser.blockStatements(Parser.java:1317)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1206)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1218)
at com.sun.tools.javac.v8.parser.Parser.statement(Parser.java:1358)
at com.sun.tools.javac.v8.parser.Parser.statement(Parser.java:1383)
at
com.sun.tools.javac.v8.parser.Parser.blockStatements(Parser.java:1274)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1206)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1218)
at com.sun.tools.javac.v8.parser.Parser.statement(Parser.java:1358)
at com.sun.tools.javac.v8.parser.Parser.statement(Parser.java:1364)
at
com.sun.tools.javac.v8.parser.Parser.blockStatements(Parser.java:1274)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1206)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1218)
at com.sun.tools.javac.v8.parser.Parser.statement(Parser.java:1358)
at com.sun.tools.javac.v8.parser.Parser.statement(Parser.java:1391)
at
com.sun.tools.javac.v8.parser.Parser.blockStatements(Parser.java:1274)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1206)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1218)
at
com.sun.tools.javac.v8.parser.Parser.methodDeclaratorRest(Parser.java:2035)
at
com.sun.tools.javac.v8.parser.Parser.classOrInterfaceBodyDeclaration(Parser.java
:1994)
at
com.sun.tools.javac.v8.parser.Parser.classOrInterfaceBody(Parser.java:1933)
at
com.sun.tools.javac.v8.parser.Parser.classDeclaration(Parser.java:1881)
at
com.sun.tools.javac.v8.parser.Parser.classOrInterfaceDeclaration(Parser.java:185
3)
at
com.sun.tools.javac.v8.parser.Parser.typeDeclaration(Parser.java:1839)
at
com.sun.tools.javac.v8.parser.Parser.compilationUnit(Parser.java:1787)
at com.sun.tools.javac.v8.JavaCompiler.parse(JavaCompiler.java:221)
at com.sun.tools.javac.v8.JavaCompiler.parse(JavaCompiler.java:245)
at com.sun.tools.javac.v8.JavaCompiler.compile(JavaCompiler.java:325)
at com.sun.tools.javac.v8.Main.compile(Main.java:567)
at com.sun.tools.javac.Main.compile(Main.java:36)
at com.sun.tools.javac.Main.main(Main.java:27)
strings into floating-point values. The existing implementation allows
integer-only strings like "1234", which is against the spec. I've fixed this
bug; but fixing this seems to cause the compiler to crash on inputs like "140d",
that is, an integer string followed by a float type suffix ('f', 'F', 'd', or
'D').
Poking around briefly, I found the following comment in Scanner.java:
/**
* The value of a literal token, recorded as a string.
* For numbers, leading 0x and 'f', 'd', 'l' suffixes are suppressed.
*/
public String stringVal() {
return new String(sbuf, 0, sp);
}
which implies the scanner/parser is stripping off the trailing type suffix
before calling parseDouble. If that is the case, it is a bug in the compiler.
I've tested the my new code separately and it behaves properly on strings like
"140d"; i.e. it accepts them but rejects "140".
Stack trace output of failing build (after gmake clobber) attached below.
Thanks,
-Joe
An exception has occurred in the compiler (1.4.1-internal). Please file a bug at
the Java Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi) after
checking the Bug Parade for duplicates. Include your program and the following
diagnostic in your report. Thank you.
java.lang.NumberFormatException: For input string: "0"
at
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at
java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1244)
at java.lang.Float.valueOf(Float.java:210)
at com.sun.tools.javac.v8.parser.Parser.literal(Parser.java:345)
at com.sun.tools.javac.v8.parser.Parser.term3(Parser.java:811)
at com.sun.tools.javac.v8.parser.Parser.term2(Parser.java:525)
at com.sun.tools.javac.v8.parser.Parser.term1(Parser.java:494)
at com.sun.tools.javac.v8.parser.Parser.term(Parser.java:435)
at com.sun.tools.javac.v8.parser.Parser.termRest(Parser.java:450)
at com.sun.tools.javac.v8.parser.Parser.term(Parser.java:438)
at com.sun.tools.javac.v8.parser.Parser.termRest(Parser.java:450)
at com.sun.tools.javac.v8.parser.Parser.term(Parser.java:438)
at com.sun.tools.javac.v8.parser.Parser.termRest(Parser.java:450)
at com.sun.tools.javac.v8.parser.Parser.term(Parser.java:438)
at com.sun.tools.javac.v8.parser.Parser.termRest(Parser.java:450)
at com.sun.tools.javac.v8.parser.Parser.term(Parser.java:438)
at com.sun.tools.javac.v8.parser.Parser.term(Parser.java:418)
at
com.sun.tools.javac.v8.parser.Parser.blockStatements(Parser.java:1317)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1206)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1218)
at com.sun.tools.javac.v8.parser.Parser.statement(Parser.java:1358)
at com.sun.tools.javac.v8.parser.Parser.statement(Parser.java:1383)
at
com.sun.tools.javac.v8.parser.Parser.blockStatements(Parser.java:1274)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1206)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1218)
at com.sun.tools.javac.v8.parser.Parser.statement(Parser.java:1358)
at com.sun.tools.javac.v8.parser.Parser.statement(Parser.java:1364)
at
com.sun.tools.javac.v8.parser.Parser.blockStatements(Parser.java:1274)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1206)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1218)
at com.sun.tools.javac.v8.parser.Parser.statement(Parser.java:1358)
at com.sun.tools.javac.v8.parser.Parser.statement(Parser.java:1391)
at
com.sun.tools.javac.v8.parser.Parser.blockStatements(Parser.java:1274)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1206)
at com.sun.tools.javac.v8.parser.Parser.block(Parser.java:1218)
at
com.sun.tools.javac.v8.parser.Parser.methodDeclaratorRest(Parser.java:2035)
at
com.sun.tools.javac.v8.parser.Parser.classOrInterfaceBodyDeclaration(Parser.java
:1994)
at
com.sun.tools.javac.v8.parser.Parser.classOrInterfaceBody(Parser.java:1933)
at
com.sun.tools.javac.v8.parser.Parser.classDeclaration(Parser.java:1881)
at
com.sun.tools.javac.v8.parser.Parser.classOrInterfaceDeclaration(Parser.java:185
3)
at
com.sun.tools.javac.v8.parser.Parser.typeDeclaration(Parser.java:1839)
at
com.sun.tools.javac.v8.parser.Parser.compilationUnit(Parser.java:1787)
at com.sun.tools.javac.v8.JavaCompiler.parse(JavaCompiler.java:221)
at com.sun.tools.javac.v8.JavaCompiler.parse(JavaCompiler.java:245)
at com.sun.tools.javac.v8.JavaCompiler.compile(JavaCompiler.java:325)
at com.sun.tools.javac.v8.Main.compile(Main.java:567)
at com.sun.tools.javac.Main.compile(Main.java:36)
at com.sun.tools.javac.Main.main(Main.java:27)