Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8284214

Add final or sealed modifier to appropriate javax.swing API classes

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • client-libs
    • None
    • source, binary
    • low
    • Hide
      If someone has circumvented package protections to subclass these, then they may no longer be able to do so. However the JDK now enforces strong encapsulation of JDK module internals, so this is not possible anyway without additional steps.

      The compatibility risk is both source and binary since as well as compile time checking of this, the VM enforces it at runtime.
      Show
      If someone has circumvented package protections to subclass these, then they may no longer be able to do so. However the JDK now enforces strong encapsulation of JDK module internals, so this is not possible anyway without additional steps. The compatibility risk is both source and binary since as well as compile time checking of this, the VM enforces it at runtime.
    • Java API
    • SE

      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

      -     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
      

      Update javax.swing.ToolTipManager

      - public class ToolTipManager extends MouseAdapter implements MouseMotionListener  
      + public final class ToolTipManager extends MouseAdapter implements MouseMotionListener  
      

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

      -     public class BasicHorizontalLayoutManager implements LayoutManager2
      +     public sealed class BasicHorizontalLayoutManager implements LayoutManager2
      +          permits BasicVerticalLayoutManager
      
      -     public class BasicVerticalLayoutManager extends
      +     public non-sealed class BasicVerticalLayoutManager extends
      

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

      - 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
      

      Update javax.swing.text.html.FormSubmitEvent to be final

      - public class FormSubmitEvent extends HTMLFrameHyperlinkEvent 
      + public final class FormSubmitEvent extends HTMLFrameHyperlinkEvent 
      

      Update nested classes of javax.swing.text.html.StyleSheet to be final

          @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 
       

            prr Philip Race
            prr Philip Race
            Alexey Ivanov, Joe Darcy, Prasanta Sadhukhan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: