Integrated: 8369489: Marker annotation on inner class access crashes javac compiler
Jan Lahoda
jlahoda at openjdk.org
Wed Nov 5 05:47:16 UTC 2025
On Fri, 17 Oct 2025 11:49:15 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.
This pull request has now been integrated.
Changeset: 8b536b54
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/8b536b5428d5bf087dc71f3559c3978b13acad16
Stats: 249 lines in 4 files changed: 240 ins; 5 del; 4 mod
8369489: Marker annotation on inner class access crashes javac compiler
Reviewed-by: vromero
-------------
PR: https://git.openjdk.org/jdk/pull/27864
More information about the compiler-dev
mailing list