Selaed classes cant permit private classes
Olexandr Rotan
rotanolexandr842 at gmail.com
Mon Aug 26 14:09:15 UTC 2024
So there is a special case for permits clause, but what about extends
clause? Should I also look into it, or, formally, this is a different issue
that requires (arguably) JLS change?
On Mon, Aug 26, 2024 at 4:51 PM Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:
>
> On 26/08/2024 14:44, Maurizio Cimadamore wrote:
>
> That is, an “extends” or “permits” clause is not really type-checked as if
> inside the body of class C. This results in the accessibility problem you
> point out (which might or might not be a compiler glitch, I don’t think the
> JLS is crystal clear on how Tmp.A should be checked).
>
> I stand corrected - see JLS 6.6:
>
> A member (class, interface, field, or method) of a class, interface, type
> parameter, or reference type, or a constructor of a class, is accessible
> only if (i) the class, interface, type parameter, or reference type is
> accessible, and (ii) the member or constructor is declared to permit
> access:
> [...]
>
> -
>
> Otherwise, the member or constructor is declared private. Access is
> permitted only when one of the following is true:
> -
>
> Access occurs from within the body of the top level class or
> interface that encloses the declaration of the member or constructor.
> - Access occurs in the permits clause of the top level class or
> interface that encloses the declaration of the member.
> -
>
> Access occurs in the record component list of the top level record
> class that encloses the declaration of the member.
>
> So, there's special accessibility pleads for "permits" clauses. So yes,
> this is a javac bug.
>
> I've added some comments to JDK-8338981.
>
> Maurizio
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240826/cb0a52f8/attachment-0001.htm>
More information about the amber-dev
mailing list