changeset 2996:3c1da6c1ef9d

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
author mcimadamore
date Thu, 30 Jul 2015 13:20:01 +0100
parents e0a4a04160cb
children 2289e78ae8b2
files src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java test/tools/javac/parser/8081769/T8081769.java test/tools/javac/parser/8081769/T8081769.out
diffstat 3 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Jul 28 17:01:45 2015 +0200
+++ b/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/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/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