JDK-8282375 : java.time.ZoneId should be a sealed abstract class
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.time
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 19
  • Submitted: 2022-02-24
  • Updated: 2022-02-26
  • Resolved: 2022-02-26
Related Reports
CSR :  
Description
Summary
-------

Change `java.time.ZoneId` to a sealed abstract class.

Problem
-------

This is a refactoring of the said class with a better construct, as the class' implementation specification has already been limiting the subclassing to two subclasses, i.e., `ZoneOffset` and `ZoneRegion`.

Solution
--------

Add `sealed` modifier to the class declaration, and permit `ZoneOffset` and `ZoneRegion` as the subclasses.

Specification
-------------

Change the declaration of the class from:
```
public abstract class ZoneId implements Serializable
```
to:
```
public abstract sealed class ZoneId implements Serializable permits ZoneOffset, ZoneRegion
```

Change the `@implSpec` in the class description to:

     * @implSpec
     * This abstract sealed class permits two implementations, both of which are immutable and
     * thread-safe. One implementation models region-based IDs, the other is {@code ZoneOffset}
     * modelling offset-based IDs. This difference is visible in serialization.


Comments
Moving to Approved. (I might quibble with the continued inclusion of some of the information the implSpec, but I realize it is consistent with the rest of the package.)
26-02-2022