Selaed classes cant permit private classes
Vicente Romero
vicente.romero at oracle.com
Mon Aug 26 14:14:40 UTC 2024
Hi Olexandr,
I will take a look at this issue, in the meantime as Maurizio commented
if you don't specify the permits clause the compiler should be able to
infer it for you,
Thanks,
Vicente
On 8/26/24 10:09, Olexandr Rotan wrote:
> 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:
>>
>> o
>>
>> Access occurs from within the body of the top level class
>> or interface that encloses the declaration of the member
>> or constructor.
>>
>> o Access occurs in the |permits| clause of the top level
>> class or interface that encloses the declaration of the
>> member.
>> o
>>
>> 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/a3ff7c9e/attachment.htm>
More information about the amber-dev
mailing list