RFR: 8246778: Compiler implementation for Sealed Classes (Second Preview) [v5]

Alan Bateman alanb at openjdk.java.net
Fri Dec 4 13:29:18 UTC 2020

On Fri, 4 Dec 2020 13:12:27 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> This pull request replaces https://github.com/openjdk/jdk/pull/1227.
>> From the original PR:
>>> Please review the code for the second iteration of sealed classes. In this iteration we are:
>>>     * Enhancing narrowing reference conversion to allow for stricter checking of cast conversions with respect to sealed type hierarchies
>>>     * Also local classes are not considered when determining implicitly declared permitted direct subclasses of a sealed class or sealed interface
>>>     * renaming Class::permittedSubclasses to Class::getPermittedSubclasses, still in the same method, the return type has been changed to Class<?>[] instead of the previous ClassDesc[]
>>>     * adding code to make sure that annotations can't be sealed
>>>     * improving some tests
>>> TIA
>>> Related specs:
>>> [Sealed Classes JSL](http://cr.openjdk.java.net/~gbierman/jep397/jep397-20201104/specs/sealed-classes-jls.html)
>>> [Sealed Classes JVMS](http://cr.openjdk.java.net/~gbierman/jep397/jep397-20201104/specs/sealed-classes-jvms.html)
>>> [Additional: Contextual Keywords](http://cr.openjdk.java.net/~gbierman/jep397/jep397-20201104/specs/contextual-keywords-jls.html)
>> This PR strives to reflect the review comments from 1227:
>>  * adjustments to javadoc of j.l.Class methods
>>  * package access checks in Class.getPermittedSubclasses()
>>  * fixed to the narrowing conversion/castability as pointed out by Maurizio
> Jan Lahoda has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR.

Marked as reviewed by alanb (Reviewer).

src/java.base/share/classes/java/lang/Class.java line 3043:

> 3041:             for (Class<?> c : subClasses) {
> 3042:                 if (Proxy.isProxyClass(c))
> 3043:                         throw new InternalError("a permitted subclass should not be a proxy class: " + c);

Minor nit but I think the indentation may be messed up here.

src/java.base/share/classes/java/lang/Class.java line 4394:

> 4392:      * implement this class or interface if it is sealed. The order of such elements
> 4393:      * is unspecified. If this {@code Class} object represents a primitive type,
> 4394:      * {@code void}, an array type, or a class or interface that is not sealed,

Did you mean {@code Void} here?

src/java.base/share/classes/java/lang/Class.java line 4403:

> 4401:      * loader} of the current {@code Class} object).
> 4402:      * The {@code Class} objects which can be obtained using this procedure,
> 4403:      * and which are direct subinterfaces or subclasses of this class or interface,

Minor suggestion is to drop "using this procedure" from this sentence.


PR: https://git.openjdk.java.net/jdk/pull/1483

More information about the compiler-dev mailing list