RFR: 8162500: Receiver annotations of inner classes of local classes not found at runtime

Chen Liang liach at openjdk.org
Tue Aug 20 03:02:50 UTC 2024


On Tue, 16 Jul 2024 18:02:57 GMT, Chen Liang <liach at openjdk.org> wrote:

> In annotated types, local and inner class types should be annotated as "top-level" types. For example, in the test here
> 
>     public static Class<?> getLocalsMember() {
>         class Local {
>             class Member {
>                 @Annot(2635) Member(@Annot(2732) Local Local.this) {}
>             }
>         }
>         return Local.Member.class;
>     }
> 
> 
> The `Local` occurrences cannot be qualified with the enclosing class type, even if the local class may be compiled to capture the enclosing class.
> 
> However, core reflection had a bug where it looks for an enclosing class instead of a declaring class; this meant that for said `Local`, core reflection was treating the outer class as the top-level in type annotations, while the top level should be the local class instead. This patch fixes this bug.

I don't think this behavior change is significant enough to merit a CSR: the old erroneous behavior did not lead to false positives that users could depend on, and this change brings core reflection closer to the language model.

Other kinds of nesting as far as I know are currently fine; local and anonymous class themselves do not have reliable receivers per language specification, and within these classes there can only be local, anonymous (which we ignore) or nested classes (which is fixed by this patch). So this covers all areas we currently care about.

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

PR Comment: https://git.openjdk.org/jdk/pull/20200#issuecomment-2297870665


More information about the core-libs-dev mailing list