JDK-8284214 : Add final or sealed modifier to appropriate javax.swing API classes
  • Type: CSR
  • Component: client-libs
  • Sub-Component: javax.swing
  • Priority: P4
  • Status: Draft
  • Resolution: Unresolved
  • Fix Versions: 19
  • Submitted: 2022-04-02
  • Updated: 2022-04-05
Related Reports
CSR :  
Description
Summary
-------

Update Swing classes to adopt the new sealed modifier, making sub-classes non-sealed of final as appropriate

Problem
-------

There are a number of Swing classes which do not permit direct application sub-classing since they do not provide public or protected constructors, but it is not as clear as it could be if they permit just some sub-classes or are effectively final.

Solution
--------

Update to use the new JEP 409 sealed and non-sealed modifiers to make the design intent clearer.

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

Update the following nested classes of javax.swing.GroupLayout as below

<pre>
-     public abstract class Group extends Spring
+     public abstract sealed class Group extends Spring
+         permits ParallelGroup,
+                 SequentialGroup

-     public class SequentialGroup extends Group
+     public final class SequentialGroup extends Group

-     public class ParallelGroup extends Group
+     public sealed class ParallelGroup extends Group
+          permits BaselineGroup

-     private class BaselineGroup extends ParallelGroup
+     private final class BaselineGroup extends ParallelGroup
</pre>

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

Update javax.swing.ToolTipManager

<pre>
- public class ToolTipManager extends MouseAdapter implements MouseMotionListener  
+ public final class ToolTipManager extends MouseAdapter implements MouseMotionListener  
</pre>

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

Update the following nested classes of javax.swing.plaf.basic.BasicSplitPaneUI

<pre>
-     public class BasicHorizontalLayoutManager implements LayoutManager2
+     public sealed class BasicHorizontalLayoutManager implements LayoutManager2
+          permits BasicVerticalLayoutManager

-     public class BasicVerticalLayoutManager extends
+     public non-sealed class BasicVerticalLayoutManager extends
</pre>

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

Update javax.swing.text.StyleConstants and its following nested classes

<pre>
- public class StyleConstants 
+ public sealed class StyleConstants
+     permits StyleConstants.CharacterConstants,
+             StyleConstants.ColorConstants,
+             StyleConstants.FontConstants,
+             StyleConstants.ParagraphConstants 

-     public static class ParagraphConstants extends StyleConstants
+     public static final class ParagraphConstants extends StyleConstants

-     public static class CharacterConstants extends StyleConstants
+     public static final class CharacterConstants extends StyleConstants


-     public static class ColorConstants extends StyleConstants
+     public static final class ColorConstants extends StyleConstants

-     public static class FontConstants extends StyleConstants
+     public static final class FontConstants extends StyleConstants
</pre>
---------

Update javax.swing.text.html.FormSubmitEvent to be final
<pre>
- public class FormSubmitEvent extends HTMLFrameHyperlinkEvent 
+ public final class FormSubmitEvent extends HTMLFrameHyperlinkEvent 
</pre>

------

Update nested classes of javax.swing.text.html.StyleSheet to be final
<pre>
    @SuppressWarnings("serial") // Same-version serialization only
-     public static class BoxPainter implements Serializable 
+     public static final class BoxPainter implements Serializable 

    @SuppressWarnings("serial") // Same-version serialization only
-     public static class ListPainter implements Serializable 
+     public static final class ListPainter implements Serializable 
 </pre>
Comments
Note that BoxPainter and ListPainter do not define a serialVersionUID but cross-version serialization is not supported.
02-04-2022