6882235: invalid exponent causes silent javac crash
authorjjg
Tue, 15 Sep 2009 12:20:55 -0700
changeset 3894 e470a29ed0a2
parent 3893 556fef8e4dbd
child 3895 3b3c2a1e5e8a
6882235: invalid exponent causes silent javac crash Reviewed-by: darcy
langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java
langtools/test/tools/javac/T6882235.java
langtools/test/tools/javac/T6882235.out
--- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Sep 14 17:13:00 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Sep 15 12:20:55 2009 -0700
@@ -593,7 +593,7 @@
 //where
         boolean isZero(String s) {
             char[] cs = s.toCharArray();
-            int base = ((Character.toLowerCase(s.charAt(1)) == 'x') ? 16 : 10);
+            int base = ((cs.length > 1 && Character.toLowerCase(cs[1]) == 'x') ? 16 : 10);
             int i = ((base==16) ? 2 : 0);
             while (i < cs.length && (cs[i] == '0' || cs[i] == '.')) i++;
             return !(i < cs.length && (Character.digit(cs[i], base) > 0));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T6882235.java	Tue Sep 15 12:20:55 2009 -0700
@@ -0,0 +1,14 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 6882235
+ * @summary invalid exponent causes silent javac crash
+ *
+ * @compile/fail T6882235.java
+ * @compile/fail/ref=T6882235.out -XDrawDiagnostics T6882235.java
+ */
+
+class T6882235 {
+    int i = ;           // invalid expression
+    float f = 0e*;      // invalid exponent, should not crash compiler
+    int j = ;           // invalid expression
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T6882235.out	Tue Sep 15 12:20:55 2009 -0700
@@ -0,0 +1,5 @@
+T6882235.java:11:13: compiler.err.illegal.start.of.expr
+T6882235.java:12:15: compiler.err.malformed.fp.lit
+T6882235.java:12:18: compiler.err.illegal.start.of.expr
+T6882235.java:13:13: compiler.err.illegal.start.of.expr
+4 errors