-
CSR
-
Resolution: Approved
-
P3
-
None
-
source, behavioral
-
minimal
-
the proposed change will increase the universe of acceptable Java programs. Thus any currently accepted Java program will continue to be so. Existing negative tests in test suites that are checking for the current behavior could fail
-
Implementation
Summary
The Javac compiler is rejecting valid programs that should be accepted according to the JLS. In particular access to private classes and interfaces should be permitted inside the permits clause of the top level class or interface enclosing the declaration of a given class or interface
Problem
The JLS 23 allows explicit permits
clauses of classes and interface to list private classes or interfaces declared inside of a given sealed class or interface. This means that programs like:
public sealed class Sealed permits Sealed.PrivateClass {
private final static class PrivateClass extends Sealed {}
}
should be accepted by javac
Solution
Synchronize the Javac compiler with section §6.6.1 of the JLS 23 specification. In particular Javac should allow explicit permits
clauses of classes and interface to list private classes or interfaces declared inside of a given sealed class or interface.
This new behavior will be present for --source 19
and later, as this was a change introduced in the JLS for version 19.
Specification
Of interest for this CSR is section §6.6.1 of the JLS 23 specification, titled: "6.6.1 Determining Accessibility" in particular where it reads:
– 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.
- csr of
-
JDK-8338981 Access to private classes should be permitted inside the permits clause of the enclosing top-level class
-
- Resolved
-