RFR: 8256266: Binding variables don't correct support declaration annotations and the final modifier [v3]

Jan Lahoda jlahoda at openjdk.java.net
Tue Dec 8 09:49:15 UTC 2020

On Mon, 7 Dec 2020 13:47:19 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>>   Fixing tests.
> src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java line 946:
>> 944:                     TreeInfo.getStartPos(pattern);
>> 945:                 } else {
>> 946:                     if (mods.annotations.nonEmpty()) {
> We don't seem to check for the source level here? E.g. is it possible that `instanceof @Foo Bar` will not issue the usual error if compiled with source != 16?

Oops. Having `instanceof @Foo Bar` is valid, due to type annotations. See e.g.:

But, when I was adding support for the final modifier on binding variables, I've forgot to disable the final modifier on non-pattern matching `instanceof`, so code like `o instanceof final String` was accepted, which is, of course, wrong.

This should be fixed by:


PR: https://git.openjdk.java.net/jdk/pull/1192

More information about the compiler-dev mailing list