On Tue, 8 Dec 2020 14:57:26 GMT, Harold Seigel <[email protected]> wrote:
>> Please review this fix for JDK-8256867. This change no longer throws a
>> ClassFormatError exception when loading a class whose PermittedSubclasses
>> attribute is empty (contains no classes). Instead, the class is treated as
>> a sealed class which cannot be extended nor implemented. This new behavior
>> conforms to the JVM Spec.
>>
>> This change required changing Class.permittedSubclasses() to return an empty
>> array for classes with empty PermittedSubclasses attributes, and to return
>> null for non-sealed classes.
>>
>> This fix was tested with Mach5 tiers 1-2 on Linux, MacOS, and Windows, and
>> tiers 3-5 on Linux x64.
>>
>> Thanks, Harold
>
> Harold Seigel has updated the pull request incrementally with one additional
> commit since the last revision:
>
> 8256867: Classes with empty PermittedSubclasses attribute cannot be extended
src/java.base/share/classes/java/lang/Class.java line 4399:
> 4397: * that is {@link #isSealed()} returns {@code false}, then this
> method returns {@code null}.
> 4398: * Conversely, if {@link #isSealed()} returns {@code true}, then
> this method
> 4399: * returns a non-null value.
@ChrisHegarty minor but I prefer a simpler alternative to address your concern
is to add a link to the reference to "sealed class or interface" to
`Class::isSealed` as follows:
implement this class or interface if it is {@linkplain #isSealed() sealed}.
The order of such elements is unspecified. If this {@code Class} object
represents a primitive type, is unspecified. The array is empty if this
{@linkplain #isSealed() sealed} class or interface has no permitted subclass.
If this {@code Class} object represents a primitive type, {@code void}, an
array type,
or a class or interface that is not sealed, then this method returns {@code
null}.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1675