-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
7
-
x86
-
linux
FULL PRODUCT VERSION :
Using "compiler-7-ea-src-b12-06_may_2007.zip" downloaded from:
http://openjdk.java.net/groups/compiler/
Running on:
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Server VM (build 1.6.0-b105, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux lahvac-laptop 2.6.20-15-generic #2 SMP Sun Apr 15 07:36:31 UTC 2007 i686 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
A StringIndexOutOfBoundsException is thrown while parsing a malformed float literal (in some circumstances). Please see the source code for the test case. See also NetBeans issue:
http://www.netbeans.org/issues/show_bug.cgi?id=98234
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The malformed float literal should be reported as an error (which really happens), no exception should be thrown.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(String.java:687)
at com.sun.tools.javac.parser.Parser.isZero(Parser.java:585)
at com.sun.tools.javac.parser.Parser.literal(Parser.java:545)
at com.sun.tools.javac.parser.Parser.term3(Parser.java:966)
at com.sun.tools.javac.parser.Parser.term2(Parser.java:700)
at com.sun.tools.javac.parser.Parser.term1(Parser.java:671)
at com.sun.tools.javac.parser.Parser.term(Parser.java:627)
at com.sun.tools.javac.parser.Parser.term(Parser.java:609)
at com.sun.tools.javac.parser.Parser.expression(Parser.java:599)
at com.sun.tools.javac.parser.Parser.arguments(Parser.java:1173)
at com.sun.tools.javac.parser.Parser.arguments(Parser.java:1188)
at com.sun.tools.javac.parser.Parser.term3(Parser.java:1004)
at com.sun.tools.javac.parser.Parser.term2(Parser.java:700)
at com.sun.tools.javac.parser.Parser.term1(Parser.java:671)
at com.sun.tools.javac.parser.Parser.term(Parser.java:627)
at com.sun.tools.javac.parser.Parser.term(Parser.java:609)
at com.sun.tools.javac.parser.Parser.blockStatements(Parser.java:1581)
at com.sun.tools.javac.parser.Parser.block(Parser.java:1498)
at com.sun.tools.javac.parser.Parser.block(Parser.java:1512)
at com.sun.tools.javac.parser.Parser.methodDeclaratorRest(Parser.java:2567)
at com.sun.tools.javac.parser.Parser.classOrInterfaceBodyDeclaration(Parser.java:2516)
at com.sun.tools.javac.parser.Parser.classOrInterfaceBody(Parser.java:2443)
at com.sun.tools.javac.parser.Parser.classDeclaration(Parser.java:2288)
at com.sun.tools.javac.parser.Parser.classOrInterfaceOrEnumDeclaration(Parser.java:2226)
at com.sun.tools.javac.parser.Parser.typeDeclaration(Parser.java:2215)
at com.sun.tools.javac.parser.Parser.compilationUnit(Parser.java:2161)
at com.sun.tools.javac.parser.EndPosParser.compilationUnit(EndPosParser.java:87)
at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:524)
at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:565)
at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:816)
at com.sun.tools.javac.api.JavacTaskImpl.parse(JavacTaskImpl.java:246)
at T9999999.main(T9999999.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:78)
at java.lang.Thread.run(Thread.java:619)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/*
* @test
* @bug 9999999
* @summary parsing source with a malformed float literal may cause exception
*/
import com.sun.tools.javac.api.JavacTaskImpl;
import java.net.URI;
import java.util.Arrays;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
public class T9999999 {
public T9999999() {
}
static class MyFileObject extends SimpleJavaFileObject {
public MyFileObject() {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
}
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return "package p; public class Test {public void test() {System.err.println(0e);}}";
}
}
public static void main(String[] args) throws Exception {
final String bootPath = System.getProperty("sun.boot.class.path"); //NOI18N
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
assert tool != null;
JavacTaskImpl ct = (JavacTaskImpl)tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath), null, Arrays.asList(new MyFileObject()));
ct.parse();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
This patch to com.sun.tools.javac.parser.Parser.java seems to fix the problem:
*** Parser.java 2007-05-10 20:53:20.000000000 +0200
--- Parser.java.bak 2007-05-10 20:53:14.000000000 +0200
***************
*** 581,586 ****
--- 581,588 ----
}
//where
boolean isZero(String s) {
+ if (s.length() == 1)
+ return '0' == s.charAt(0);
char[] cs = s.toCharArray();
int base = ((Character.toLowerCase(s.charAt(1)) == 'x') ? 16 : 10);
int i = ((base==16) ? 2 : 0);
Using "compiler-7-ea-src-b12-06_may_2007.zip" downloaded from:
http://openjdk.java.net/groups/compiler/
Running on:
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Server VM (build 1.6.0-b105, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux lahvac-laptop 2.6.20-15-generic #2 SMP Sun Apr 15 07:36:31 UTC 2007 i686 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
A StringIndexOutOfBoundsException is thrown while parsing a malformed float literal (in some circumstances). Please see the source code for the test case. See also NetBeans issue:
http://www.netbeans.org/issues/show_bug.cgi?id=98234
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The malformed float literal should be reported as an error (which really happens), no exception should be thrown.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(String.java:687)
at com.sun.tools.javac.parser.Parser.isZero(Parser.java:585)
at com.sun.tools.javac.parser.Parser.literal(Parser.java:545)
at com.sun.tools.javac.parser.Parser.term3(Parser.java:966)
at com.sun.tools.javac.parser.Parser.term2(Parser.java:700)
at com.sun.tools.javac.parser.Parser.term1(Parser.java:671)
at com.sun.tools.javac.parser.Parser.term(Parser.java:627)
at com.sun.tools.javac.parser.Parser.term(Parser.java:609)
at com.sun.tools.javac.parser.Parser.expression(Parser.java:599)
at com.sun.tools.javac.parser.Parser.arguments(Parser.java:1173)
at com.sun.tools.javac.parser.Parser.arguments(Parser.java:1188)
at com.sun.tools.javac.parser.Parser.term3(Parser.java:1004)
at com.sun.tools.javac.parser.Parser.term2(Parser.java:700)
at com.sun.tools.javac.parser.Parser.term1(Parser.java:671)
at com.sun.tools.javac.parser.Parser.term(Parser.java:627)
at com.sun.tools.javac.parser.Parser.term(Parser.java:609)
at com.sun.tools.javac.parser.Parser.blockStatements(Parser.java:1581)
at com.sun.tools.javac.parser.Parser.block(Parser.java:1498)
at com.sun.tools.javac.parser.Parser.block(Parser.java:1512)
at com.sun.tools.javac.parser.Parser.methodDeclaratorRest(Parser.java:2567)
at com.sun.tools.javac.parser.Parser.classOrInterfaceBodyDeclaration(Parser.java:2516)
at com.sun.tools.javac.parser.Parser.classOrInterfaceBody(Parser.java:2443)
at com.sun.tools.javac.parser.Parser.classDeclaration(Parser.java:2288)
at com.sun.tools.javac.parser.Parser.classOrInterfaceOrEnumDeclaration(Parser.java:2226)
at com.sun.tools.javac.parser.Parser.typeDeclaration(Parser.java:2215)
at com.sun.tools.javac.parser.Parser.compilationUnit(Parser.java:2161)
at com.sun.tools.javac.parser.EndPosParser.compilationUnit(EndPosParser.java:87)
at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:524)
at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:565)
at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:816)
at com.sun.tools.javac.api.JavacTaskImpl.parse(JavacTaskImpl.java:246)
at T9999999.main(T9999999.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:78)
at java.lang.Thread.run(Thread.java:619)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/*
* @test
* @bug 9999999
* @summary parsing source with a malformed float literal may cause exception
*/
import com.sun.tools.javac.api.JavacTaskImpl;
import java.net.URI;
import java.util.Arrays;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
public class T9999999 {
public T9999999() {
}
static class MyFileObject extends SimpleJavaFileObject {
public MyFileObject() {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
}
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return "package p; public class Test {public void test() {System.err.println(0e);}}";
}
}
public static void main(String[] args) throws Exception {
final String bootPath = System.getProperty("sun.boot.class.path"); //NOI18N
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
assert tool != null;
JavacTaskImpl ct = (JavacTaskImpl)tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath), null, Arrays.asList(new MyFileObject()));
ct.parse();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
This patch to com.sun.tools.javac.parser.Parser.java seems to fix the problem:
*** Parser.java 2007-05-10 20:53:20.000000000 +0200
--- Parser.java.bak 2007-05-10 20:53:14.000000000 +0200
***************
*** 581,586 ****
--- 581,588 ----
}
//where
boolean isZero(String s) {
+ if (s.length() == 1)
+ return '0' == s.charAt(0);
char[] cs = s.toCharArray();
int base = ((Character.toLowerCase(s.charAt(1)) == 'x') ? 16 : 10);
int i = ((base==16) ? 2 : 0);
- duplicates
-
JDK-6882235 invalid exponent causes silent javac crash
-
- Closed
-