JDK-8283700 : Add final or sealed modifier to appropriate java.awt API classes
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 19
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2022-03-25
  • Updated: 2022-03-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 19
19Unresolved
Related Reports
CSR :  
Relates :  
Description
JDK 17 delivered JEP 409: Sealed Classes : https://openjdk.java.net/jeps/409
As well as being used for future classes this can be retrofitted to
suitable existing API classes where provably there can be no application
sub-classes since there are no public or protected constructors and
at least one package access constructor

A scan for these has identified various classes in the desktop module as candidates
Some of these turn out to have no subclasses and these should be marked final instead
of sealed.

Not all classes that can be sealed may be worth the effort or seem appropriate
They maybe classes that simply happen to have a limited set of subclasses
currently defined but have no natural set, and absence of public and protected constructors
already is sufficient.
Or they may have internal platform-specific sub-classes which require special treatment
That is, a sealed class must declare which classes it permits to sub-class, and those
classes must be accessible at compile time. A platform-specific subclass will not
be present except on that platform so the code will fail to compile on other platforms.
Solutions would either be to move the platform class to shared code - not always
appropriate, or to introduce a shared subclass which is un-sealed but otherwise
unchanged and then have the platform classes extend that.

These are possible of course, but it maybe a question of whether it is worth it.

For AWT the candidate classes are below and are annotated either FINAL or SEALED
to indicate the treatment they should receive.

FINAL java.awt.GridBagLayoutInfo
FINAL java.awt.PointerInfo
FINAL java.awt.ScrollPaneAdjustable
SEALED java.awt.TextComponent
SEALED java.awt.desktop.AppEvent
SEALED java.awt.desktop.FilesEvent
FINAL java.awt.dnd.DropTargetContext
SEALED java.awt.event.InputEvent

Comments
A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/7998 Date: 2022-03-28 16:30:50 +0000
28-03-2022

For TextComponent and InputEvent we can seal to permit just the direct subclasses. But their public sub-classes will need to be non-sealed, since they have public constructors.
28-03-2022