8081769: Redundant error message on bad usage of 'class' literal
authormcimadamore
Thu, 30 Jul 2015 13:20:01 +0100
changeset 31939 89d4a8756f98
parent 31938 12e1a8e258e0
child 31940 e3e48135dbfc
8081769: Redundant error message on bad usage of 'class' literal Summary: javac should skip to next token when an erroneous ident is found in term3rest Reviewed-by: jlahoda
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
langtools/test/tools/javac/parser/8081769/T8081769.java
langtools/test/tools/javac/parser/8081769/T8081769.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Jul 28 17:01:45 2015 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Jul 30 13:20:01 2015 +0100
@@ -581,6 +581,10 @@
      * Ident = IDENTIFIER
      */
     protected Name ident() {
+        return ident(false);
+    }
+
+    protected Name ident(boolean advanceOnErrors) {
         if (token.kind == IDENTIFIER) {
             Name name = token.name();
             nextToken();
@@ -616,6 +620,9 @@
             return name;
         } else {
             accept(IDENTIFIER);
+            if (advanceOnErrors) {
+                nextToken();
+            }
             return names.error;
         }
     }
@@ -1413,7 +1420,7 @@
                         // is the mode check needed?
                         tyannos = typeAnnotationsOpt();
                     }
-                    t = toP(F.at(pos1).Select(t, ident()));
+                    t = toP(F.at(pos1).Select(t, ident(true)));
                     if (tyannos != null && tyannos.nonEmpty()) {
                         t = toP(F.at(tyannos.head.pos).AnnotatedType(tyannos, t));
                     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/parser/8081769/T8081769.java	Thu Jul 30 13:20:01 2015 +0100
@@ -0,0 +1,16 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8081769
+ * @summary Redundant error message on bad usage of 'class' literal
+ * @compile/fail/ref=T8081769.out -XDrawDiagnostics T8081769.java
+ */
+class T8081769 {
+    void test() {
+        Class c1 = this.class;
+        Class c2 = "".class;
+        Class c3 = 0 .class;
+        Class c4 = null.class;
+        Object x;
+        Class c5 = x.toString().class;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/parser/8081769/T8081769.out	Thu Jul 30 13:20:01 2015 +0100
@@ -0,0 +1,6 @@
+T8081769.java:9:25: compiler.err.expected: token.identifier
+T8081769.java:10:23: compiler.err.expected: token.identifier
+T8081769.java:11:23: compiler.err.expected: token.identifier
+T8081769.java:12:25: compiler.err.expected: token.identifier
+T8081769.java:14:33: compiler.err.expected: token.identifier
+5 errors