RFR: 8369489: Marker annotation on inner class access crashes javac compiler [v2]
Jan Lahoda
jlahoda at openjdk.org
Tue Nov 4 14:53:32 UTC 2025
> 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
-------------
Changes: https://git.openjdk.org/jdk/pull/27864/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=27864&range=01
Stats: 249 lines in 4 files changed: 240 ins; 5 del; 4 mod
Patch: https://git.openjdk.org/jdk/pull/27864.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/27864/head:pull/27864
PR: https://git.openjdk.org/jdk/pull/27864
More information about the compiler-dev
mailing list