RFR: 8369489: Marker annotation on inner class access crashes javac compiler [v2]

Vicente Romero vromero at openjdk.org
Tue Nov 4 18:30:08 UTC 2025


On Tue, 4 Nov 2025 14:53:32 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> Consider code like:
>> 
>> I i = @Ann Object[]::new;
>> 
>> 
>> the initializer is a method reference over an array type, whose component is annotated - that follows from the grammar in JLS 4.3, and also matches what is parsed for code like:
>> 
>> I i = (@Ann Object[]) null;
>> 
>> 
>> But, the javac's parser will create a method reference, whose type is an annotated type - which is wrong. And also fails if the array type as such is also annotated.
>> 
>> The proposal herein is to simply use `insertAnnotationsToMostInner` to put the annotation at the correct place, as is done on other similar places. This one attaches the annotation at the correct nesting level.
>> 
>> Sadly, the code may be something very broken like:
>> 
>> I i = @Ann foobar()::new;
>> 
>> 
>> and `insertAnnotationsToMostInner` would fail for this code/AST. Hence if the method reference is not over a type, we'll create an `AnnotatedType` (to keep the info in the AST as before) + an error + an error AST node.
>
> Jan Lahoda has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains four commits:
> 
>  - Merge branch 'master' into JDK-8369489
>  - Fixing error recovery.
>  - Adjusting member ref position to sensible values.
>  - 8369489: Marker annotation on inner class access crashes javac compiler

lgtm

-------------

Marked as reviewed by vromero (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/27864#pullrequestreview-3418109245


More information about the compiler-dev mailing list