RFR: 8282572: EnumSet should be a sealed class

Jaikiran Pai jpai at openjdk.java.net
Tue Mar 8 10:57:25 UTC 2022


Can I please get a review of this change which proposes to implement the enhancement requested in https://bugs.openjdk.java.net/browse/JDK-8282572?

The (public) `EnumSet` class has 2 package private (JDK) internal sub-classes - the `JumboEnumSet` and `RegularEnumSet`. These 2 classes don't have any sub-classes of their own. 

In this commit, the `EnumSet` is marked as `sealed` and the `JumboEnumSet` and `RegularEnumSet` are the two permitted sub classes.  Both of these sub-classes are now marked as `final` too. Usage of `non-sealed` modifier for these 2 sub-classes was an option too. But I decided to start with the more restrictive option since we don't have any other sub-classes and if and when we do have their sub-classes, it's possible to change them to `non-sealed`.

The `EnumSet` class implements the `java.io.Serializable` interface. As part of this change, manual tests have been run to make sure that changing this class to `sealed` and marking the sub-classes as `final` don't break any serialization/deserialization semantics, across Java version and/or user application versions.

`tier1` testing across various platforms is currently in progress.

-------------

Commit messages:
 - 8282572: EnumSet should be a sealed class

Changes: https://git.openjdk.java.net/jdk/pull/7741/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=7741&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8282572
  Stats: 7 lines in 3 files changed: 0 ins; 0 del; 7 mod
  Patch: https://git.openjdk.java.net/jdk/pull/7741.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/7741/head:pull/7741

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


More information about the core-libs-dev mailing list