Description
Based on:
https://mail.openjdk.org/pipermail/amber-dev/2024-August/008911.html
Consider this code:
```
public sealed class Perm permits Perm.C {
private final static class C extends Perm {}
}
```
Compiling it leads to:
```
$ ./javac -fullversion
javac full version "23+37-2369"
$ ./javac /tmp/Perm.java
/tmp/Perm.java:1: error: C has private access in Perm
public sealed class Perm permits Perm.C {
^
/tmp/Perm.java:2: error: class is not allowed to extend sealed class: Perm (as it is not listed in its 'permits' clause)
private final static class C extends Perm {}
^
2 errors
```
This is not correct based on the current specification. JLS 8.1.6 says:
Every TypeName must name an accessible class (§6.6), or a compile-time error occurs.
And JLS 6.6.1 says:
Otherwise, the member or constructor is declared private. Access is permitted only when one of the following is true:
...
Access occurs in the permits clause of the top level class or interface that encloses the declaration of the member.
...
So, it appears that the "C" class should be accessible inside the permitted clause. Please seeJDK-8284011.
https://mail.openjdk.org/pipermail/amber-dev/2024-August/008911.html
Consider this code:
```
public sealed class Perm permits Perm.C {
private final static class C extends Perm {}
}
```
Compiling it leads to:
```
$ ./javac -fullversion
javac full version "23+37-2369"
$ ./javac /tmp/Perm.java
/tmp/Perm.java:1: error: C has private access in Perm
public sealed class Perm permits Perm.C {
^
/tmp/Perm.java:2: error: class is not allowed to extend sealed class: Perm (as it is not listed in its 'permits' clause)
private final static class C extends Perm {}
^
2 errors
```
This is not correct based on the current specification. JLS 8.1.6 says:
Every TypeName must name an accessible class (§6.6), or a compile-time error occurs.
And JLS 6.6.1 says:
Otherwise, the member or constructor is declared private. Access is permitted only when one of the following is true:
...
Access occurs in the permits clause of the top level class or interface that encloses the declaration of the member.
...
So, it appears that the "C" class should be accessible inside the permitted clause. Please see
Attachments
Issue Links
- relates to
-
JDK-8284011 6.6.1: Clarify that a private member class can be used in a permits clause and as a record component
- Resolved
- links to
-
Review(master) openjdk/jdk/20718