[PATCH] 8081769: Redundant error message on bad usage of class literal

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Jul 30 16:06:04 UTC 2015


Hi,
I've just pushed a fix for this issue - unfortunately the proposed fix 
was causing too many regressions in existing tests - i.e. cases where 
the new output was worse than the old one. So I settled for a more 
localized fix.

http://hg.openjdk.java.net/jdk9/dev/langtools/rev/3c1da6c1ef9d

Thanks!

Maurizio

On 29/06/15 14:27, Maurizio Cimadamore wrote:
> 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