On Sat, 7 Mar 2026 00:01:41 GMT, Chen Liang <[email protected]> wrote:
> In the Java Platform, most bootstrap method declarations are declared in Java
> source code. Each of these bootstrap method need to refer to the bootstrap
> method mechanism, which makes documentation repetitive, and not
> straightforward when seen from source code. This demand came out of recent PR
> reviews like #30067.
>
> We can introduce documented annotations so the bootstrap method role becomes
> straightforward. The Java compilers can also emit warnings for these
> annotations to make sure the annotated declarations are not definitely
> illegal.
>
> In this RFE, javac will provide basic warnings under the new "bsm" lint
> category to validate these annotations for source levels 27 and above. The
> lint category will be on by default, and won't affect `-Xlint:all` usages for
> source levels 26 and below.
test/langtools/tools/javac/meth/BootstrapAnnos/BadBootstrapAnnotations.out line
6:
> 4: BadBootstrapAnnotations.java:23:5: compiler.warn.not.bootstrap.method:
> kindname.method, BadBootstrapAnnotations(), (compiler.misc.dynamic.constant)
> 5: BadBootstrapAnnotations.java:27:5: compiler.warn.not.bootstrap.method:
> kindname.method,
> nonStaticBoot(java.lang.invoke.MethodHandles.Lookup,java.lang.String,java.lang.invoke.MethodType),
> (compiler.misc.dynamic.call.site)
> 6: BadBootstrapAnnotations.java:27:24: compiler.warn.not.bootstrap.method:
> kindname.method,
> nonStaticBoot(java.lang.invoke.MethodHandles.Lookup,java.lang.String,java.lang.invoke.MethodType),
> (compiler.misc.dynamic.constant)
So we do throw warnings for instance methods? The javadoc on the annotation
seems to imply that instance methods are alright, or does the receiver have to
be MethodHandles.Lookup?
test/langtools/tools/javac/meth/BootstrapAnnos/GoodBootstrapAnnotations.java
line 68:
> 66: // weird condys
> 67: @ConstantBootstrap static void constNull(MethodHandles.Lookup l,
> Object... o) {}
> 68: }
Could you add a 'good' example of instance bootstrap method as well?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/30125#discussion_r2927757129
PR Review Comment: https://git.openjdk.org/jdk/pull/30125#discussion_r2927764272