[PATCH] 8081769: Redundant error message on bad usage of class literal
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Jun 29 13:27:58 UTC 2015
Thanks - this looks solid; I will double check the patch, run all
required tests and integrate it (if all test pass :-))
Regards
Maurizio
On 25/06/15 15:58, bsrbnd wrote:
> 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