RFR: 8246778: Compiler implementation for Sealed Classes (Second Preview)
Jan Lahoda
jlahoda at openjdk.java.net
Thu Dec 3 14:40:55 UTC 2020
On Thu, 3 Dec 2020 14:08:48 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
>>> I suggest `Class::getPermittedSubclasses` to return a `non-null` array if this `Class` is sealed, i.e. this class is derived from a `class` file with the presence of `PermittedSubclasses` attribute regardless of its content (the attribute could be empty or contains zero or more entries which is a properly loaded permitted subtype.
>>>
>>> If this `Class` is not sealed, `Class::getPermittedSubclasses` returns null (see `Class::getRecordComponents` and some other reflection APIs as precedence).
>>
>> Agree, that seems reasonable. Often, methods in `Class` with an array return type default to an empty array, but `getRecordComponents` is a good example of returning `null` when an empty array is meaningful.
>
> I've changed Class.getPermittedSubclasses to return null for classes that are not sealed here:
> https://github.com/openjdk/jdk/pull/1483/commits/7056143822ff62dfbb1d294c67352ed3892317c2
> with follow-up changes to tests here:
> https://github.com/openjdk/jdk/pull/1483/commits/537e267fb6802ab5cf38bf26978039383cc6309a
>
> How does this look?
After a discussion with Harold, I've reverted the patch where Class.getPermittedSubclasses returns null. Harold will do that separatelly under JDK-8256867, unless there are objections.
The changes that were reverted are still available here:
https://openjdk.github.io/cr/?repo=jdk&pr=1483&range=02-03
Please let me know if there are any issues.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1483
More information about the core-libs-dev
mailing list