[PATCH] 8081769: Redundant error message on bad usage of class literal
bsrbnd
bsrbnd at gmail.com
Thu Jun 25 14:58:32 UTC 2015
Hi,
as described in issue 8081769, the following code produces two errors
instead of one plus a wrong end of file error.
public class BadClassLiteral {
public static void method() {
Class c1 = this.class;
}
}
BadClassLiteral.java:3: error: <identifier> expected
Class c1 = this.class;
^
BadClassLiteral.java:3: error: <identifier> expected
Class c1 = this.class;
^
BadClassLiteral.java:5: error: reached end of file while parsing
}
^
3 errors
While the first error is ok, the second and third errors occured
because the parser goes on with a class definition starting with the
"class" token.
Method JavacParser.accept(TokenKind) should skip next token ("class"
in this case) even if an error occurs, as follows (jdk 9):
diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
@@ -485,6 +485,7 @@
} else {
setErrorEndPos(token.pos);
reportSyntaxError(S.prevToken().endPos, "expected", tk);
+ nextToken();
}
}
Regards,
bsrbnd
More information about the compiler-dev
mailing list