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

Address reliance on default constructors in the javax.swing.plaf.basic APIs

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 16
    • client-libs
    • None
    • source
    • minimal
    • Add explicit constructors equivalent to default constructors
    • Java API
    • SE

      Summary

      Add explicit constructors to API classes of javax.swing.plaf.synth that have default constructors

      Problem

      Default constructors are not recommended for classes that are parts of a formal API.

      Solution

      Add explicit public no-arg constructors for public classes and protected no-arg constructor for public abstract classes.

      Specification

      -

      -- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLabelUI.java  2020-08-15 15:42:11.683968100 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLabelUI.java 2020-08-15 15:42:08.613675400 +0530
      @@ -71,6 +71,11 @@
           private Rectangle paintIconR = new Rectangle();
           private Rectangle paintTextR = new Rectangle();
      
      +    /**
      +     * Constructs a {@code BasicLabelUI}.
      +     */
      +    public BasicLabelUI() {}
      +
           static void loadActionMap(LazyActionMap map) {
               map.put(new Actions(Actions.PRESS));
               map.put(new Actions(Actions.RELEASE));
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicListUI.java  2020-08-15 15:42:29.782113500 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicListUI.java  2020-08-15 15:42:26.721158800 +0530
      @@ -199,6 +199,11 @@
      
           private static final int DROP_LINE_THICKNESS = 2;
      
      +    /**
      +     * Constructs a {@code BasicListUI}.
      +     */
      +    public BasicListUI() {}
      +
           static void loadActionMap(LazyActionMap map) {
               map.put(new Actions(Actions.SELECT_PREVIOUS_COLUMN));
               map.put(new Actions(Actions.SELECT_PREVIOUS_COLUMN_EXTEND));
      @@ -1577,6 +1582,11 @@
           @SuppressWarnings("serial") // Same-version serialization only
           public class MouseInputHandler implements MouseInputListener
           {
      +        /**
      +         * Constructs a {@code MouseInputHandler}.
      +         */
      +        public MouseInputHandler() {}
      +
               public void mouseClicked(MouseEvent e) {
                   getHandler().mouseClicked(e);
               }
      @@ -1641,6 +1651,11 @@
           public class FocusHandler implements FocusListener
           {
               /**
      +         * Constructs a {@code FocusHandler}.
      +         */
      +        public FocusHandler() {}
      +
      +        /**
                * Repaints focused cells.
                */
               protected void repaintCellFocus()
      @@ -1691,6 +1706,11 @@
           @SuppressWarnings("serial") // Same-version serialization only
           public class ListSelectionHandler implements ListSelectionListener
           {
      +        /**
      +         * Constructs a {@code ListSelectionHandler}.
      +         */
      +        public ListSelectionHandler() {}
      +
               public void valueChanged(ListSelectionEvent e)
               {
                   getHandler().valueChanged(e);
      @@ -1752,6 +1772,11 @@
           @SuppressWarnings("serial") // Same-version serialization only
           public class ListDataHandler implements ListDataListener
           {
      +        /**
      +         * Constructs a {@code ListDataHandler}.
      +         */
      +        public ListDataHandler() {}
      +
               public void intervalAdded(ListDataEvent e) {
                   getHandler().intervalAdded(e);
               }
      @@ -1820,6 +1845,11 @@
           @SuppressWarnings("serial") // Same-version serialization only
           public class PropertyChangeHandler implements PropertyChangeListener
           {
      +        /**
      +         * Constructs a {@code PropertyChangeHandler}.
      +         */
      +        public PropertyChangeHandler() {}
      +
               public void propertyChange(PropertyChangeEvent e)
               {
                   getHandler().propertyChange(e);
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java 2020-08-15 15:42:48.034761700 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java 2020-08-15 15:42:44.929190700 +0530
      @@ -128,6 +128,11 @@
           private PropertyChangeListener disposer = null;
      
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected BasicLookAndFeel() {}
      +
      +    /**
            * Returns the look and feel defaults. The returned {@code UIDefaults}
            * is populated by invoking, in order, {@code initClassDefaults},
            * {@code initSystemColorDefaults} and {@code initComponentDefaults}.
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuBarUI.java   2020-08-15 15:43:05.880475100 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuBarUI.java   2020-08-15 15:43:02.896892100 +0530
      @@ -72,6 +72,11 @@
           private Handler handler;
      
           /**
      +     * Constructs a {@code BasicMenuBarUI}.
      +     */
      +    public BasicMenuBarUI() {}
      +
      +    /**
            * Returns a new instance of {@code BasicMenuBarUI}.
            *
            * @param x a component
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java  2020-08-15 15:43:23.720213000 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java  2020-08-15 15:43:20.581666800 +0530
      @@ -131,6 +131,11 @@
           private static final boolean VERBOSE = false; // show reuse hits/misses
           private static final boolean DEBUG =   false;  // show bad params, misc.
      
      +    /**
      +     * Constructs a {@code BasicMenuItemUI}.
      +     */
      +    public BasicMenuItemUI() {}
      +
           static void loadActionMap(LazyActionMap map) {
               // NOTE: BasicMenuUI also calls into this method.
               map.put(new Actions(Actions.CLICK));
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuUI.java  2020-08-15 15:43:41.260590500 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuUI.java  2020-08-15 15:43:38.183946100 +0530
      @@ -71,6 +71,11 @@
           private static boolean crossMenuMnemonic = true;
      
           /**
      +     * Constructs a {@code BasicMenuUI}.
      +     */
      +    public BasicMenuUI() {}
      +
      +    /**
            * Constructs a new instance of {@code BasicMenuUI}.
            *
            * @param x a component
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicOptionPaneUI.java    2020-08-15 15:43:59.455573500 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicOptionPaneUI.java    2020-08-15 15:43:56.271771100 +0530
      @@ -127,6 +127,11 @@
               }
           }
      
      +    /**
      +     * Constructs a {@code BasicOptionPaneUI}.
      +     */
      +    public BasicOptionPaneUI() {}
      +
           static void loadActionMap(LazyActionMap map) {
               map.put(new Actions(Actions.CLOSE));
               BasicLookAndFeel.installAudioActionMap(map);
      @@ -1258,6 +1263,11 @@
            */
           public class PropertyChangeHandler implements PropertyChangeListener {
               /**
      +         * Constructs a {@code PropertyChangeHandler}.
      +         */
      +        public PropertyChangeHandler() {}
      +
      +        /**
                * If the source of the PropertyChangeEvent <code>e</code> equals the
                * optionPane and is one of the ICON_PROPERTY, MESSAGE_PROPERTY,
                * OPTIONS_PROPERTY or INITIAL_VALUE_PROPERTY,
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPanelUI.java 2020-08-15 15:44:18.972707000 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPanelUI.java 2020-08-15 15:44:15.831088600 +0530
      @@ -44,6 +44,11 @@
           private static PanelUI panelUI;
      
           /**
      +     * Constructs a {@code BasicPanelUI}.
      +     */
      +    public BasicPanelUI() {}
      +
      +    /**
            * Returns an instance of {@code BasicPanelUI}.
            *
            * @param c a component
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPasswordFieldUI.java 2020-08-15 15:44:36.375983900 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPasswordFieldUI.java 2020-08-15 15:44:33.435677800 +0530
      @@ -43,6 +43,11 @@
       public class BasicPasswordFieldUI extends BasicTextFieldUI {
      
           /**
      +     * Constructs a {@code BasicPasswordFieldUI}.
      +     */
      +    public BasicPasswordFieldUI() {}
      +
      +    /**
            * Creates a UI for a JPasswordField.
            *
            * @param c the JPasswordField
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java    2020-08-15 15:44:54.537802500 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java    2020-08-15 15:44:51.336025200 +0530
      @@ -43,6 +43,11 @@
       public class BasicPopupMenuSeparatorUI extends BasicSeparatorUI
       {
           /**
      +     * Constructs a {@code BasicPopupMenuSeparatorUI}.
      +     */
      +    public BasicPopupMenuSeparatorUI() {}
      +
      +    /**
            * Returns a new instance of {@code BasicPopupMenuSeparatorUI}.
            *
            * @param c a component
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicProgressBarUI.java   2020-08-15 15:45:11.601284200 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicProgressBarUI.java   2020-08-15 15:45:08.653175900 +0530
      @@ -134,6 +134,11 @@
           private int maxPosition = 0; //maximum X (horiz) or Y box location
      
           /**
      +     * Constructs a {@code BasicProgressBarUI}.
      +     */
      +    public BasicProgressBarUI() {}
      +
      +    /**
            * Returns a new instance of {@code BasicProgressBarUI}.
            *
            * @param x a component
      @@ -1288,6 +1293,11 @@
            * Instantiate it only within subclasses of {@code BasicProgressBarUI}.
            */
           public class ChangeHandler implements ChangeListener {
      +        /**
      +         * Constructs a {@code ChangeHandler}.
      +         */
      +        public ChangeHandler() {}
      +
               // NOTE: This class exists only for backward compatibility. All
               // its functionality has been moved into Handler. If you need to add
               // new functionality add it to the Handler, but make sure this
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java   2020-08-15 15:45:29.391571000 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java   2020-08-15 15:45:26.356677000 +0530
      @@ -40,6 +40,11 @@
       public class BasicRadioButtonMenuItemUI extends BasicMenuItemUI
       {
           /**
      +     * Constructs a {@code BasicRadioButtonMenuItemUI}.
      +     */
      +    public BasicRadioButtonMenuItemUI() {}
      +
      +    /**
            * Returns a new instance of {@code BasicRadioButtonMenuItemUI}.
            *
            * @param b a component
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicRadioButtonUI.java   2020-08-15 15:45:47.561327700 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicRadioButtonUI.java   2020-08-15 15:45:44.231523900 +0530
      @@ -62,6 +62,11 @@
           // ********************************
      
           /**
      +     * Constructs a {@code BasicRadioButtonUI}.
      +     */
      +    public BasicRadioButtonUI() {}
      +
      +    /**
            * Returns an instance of {@code BasicRadioButtonUI}.
            *
            * @param b a component
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicRootPaneUI.java  2020-08-15 15:46:05.188080500 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicRootPaneUI.java  2020-08-15 15:46:02.236506900 +0530
      @@ -49,6 +49,11 @@
           private static RootPaneUI rootPaneUI = new BasicRootPaneUI();
      
           /**
      +     * Constructs a {@code BasicRootPaneUI}.
      +     */
      +    public BasicRootPaneUI() {}
      +
      +    /**
            * Returns a new instance of {@code BasicRootPaneUI}.
            *
            * @param c a component
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java 2020-08-15 15:46:23.372114800 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java 2020-08-15 15:46:20.111740700 +0530
      @@ -163,6 +163,11 @@
            */
           protected int decrGap;
      
      +    /**
      +     * Constructs a {@code BasicScrollBarUI}.
      +     */
      +    public BasicScrollBarUI() {}
      +
           static void loadActionMap(LazyActionMap map) {
               map.put(new Actions(Actions.POSITIVE_UNIT_INCREMENT));
               map.put(new Actions(Actions.POSITIVE_BLOCK_INCREMENT));
      @@ -1645,6 +1650,11 @@
           /** Property change handler */
           public class PropertyChangeHandler implements PropertyChangeListener
           {
      +        /**
      +         * Constructs a {@code PropertyChangeHandler}.
      +         */
      +        public PropertyChangeHandler() {}
      +
               // NOTE: This class exists only for backward compatibility. All
               // its functionality has been moved into Handler. If you need to add
               // new functionality add it to the Handler, but make sure this
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java    2020-08-15 15:46:43.219352300 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java    2020-08-15 15:46:39.647810800 +0530
      @@ -99,6 +99,11 @@
           private boolean setValueCalled = false;
      
           /**
      +     * Constructs a {@code BasicScrollPaneUI}.
      +     */
      +    public BasicScrollPaneUI() {}
      +
      +    /**
            * Returns a new instance of {@code BasicScrollPaneUI}.
            *
            * @param x a component.
      @@ -494,6 +499,10 @@
            */
           public class ViewportChangeHandler implements ChangeListener
           {
      +        /**
      +         * Constructs a {@code ViewportChangeHandler}.
      +         */
      +        public ViewportChangeHandler() {}
      
               // NOTE: This class exists only for backward compatibility. All
               // its functionality has been moved into Handler. If you need to add
      @@ -520,6 +529,10 @@
            */
           public class HSBChangeListener implements ChangeListener
           {
      +        /**
      +         * Constructs a {@code HSBChangeListener}.
      +         */
      +        public HSBChangeListener() {}
      
               // NOTE: This class exists only for backward compatibility. All
               // its functionality has been moved into Handler. If you need to add
      @@ -555,6 +568,10 @@
            */
           public class VSBChangeListener implements ChangeListener
           {
      +        /**
      +         * Constructs a {@code VSBChangeListener}.
      +         */
      +        public VSBChangeListener() {}
      
               // NOTE: This class exists only for backward compatibility. All
               // its functionality has been moved into Handler. If you need to add
      @@ -751,6 +768,10 @@
            */
           public class PropertyChangeHandler implements PropertyChangeListener
           {
      +        /**
      +         * Constructs a {@code PropertyChangeHandler}.
      +         */
      +        public PropertyChangeHandler() {}
      
               // NOTE: This class exists only for backward compatibility. All
               // its functionality has been moved into Handler. If you need to add
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSeparatorUI.java 2020-08-15 15:47:04.596405300 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSeparatorUI.java 2020-08-15 15:47:01.231947100 +0530
      @@ -56,6 +56,11 @@
           protected Color highlight;
      
           /**
      +     * Constructs a {@code BasicSeparatorUI}.
      +     */
      +    public BasicSeparatorUI() {}
      +
      +    /**
            * Returns a new instance of {@code BasicSeparatorUI}.
            *
            * @param c a component
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSliderUI.java    2020-08-15 15:47:23.857616100 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSliderUI.java    2020-08-15 15:47:20.244671700 +0530
      @@ -117,6 +117,11 @@
           private boolean sameLabelBaselines;
      
           /**
      +     * Constructs a {@code BasicSliderUI}.
      +     */
      +    public BasicSliderUI() {}
      +
      +    /**
            * Returns the shadow color.
            * @return the shadow color
            */
      @@ -918,6 +923,11 @@
            * A property change handler.
            */
           public class PropertyChangeHandler implements PropertyChangeListener {
      +        /**
      +         * Constructs a {@code PropertyChangeHandler}.
      +         */
      +        public PropertyChangeHandler() {}
      +
               // NOTE: This class exists only for backward compatibility. All
               // its functionality has been moved into Handler. If you need to add
               // new functionality add it to the Handler, but make sure this
      @@ -1863,6 +1873,11 @@
            * Instantiate it only within subclasses of <code>Foo</code>.
            */
           public class ChangeHandler implements ChangeListener {
      +        /**
      +         * Constructs a {@code ChangeHandler}.
      +         */
      +        public ChangeHandler() {}
      +
               // NOTE: This class exists only for backward compatibility. All
               // its functionality has been moved into Handler. If you need to add
               // new functionality add it to the Handler, but make sure this
      @@ -1890,6 +1905,11 @@
               protected transient int currentMouseY;
      
               /**
      +         * Constructs a {@code TrackListener}.
      +         */
      +        public TrackListener() {}
      +
      +        /**
                * {@inheritDoc}
                */
               public void mouseReleased(MouseEvent e) {
      @@ -2200,6 +2220,11 @@
            * Instantiate it only within subclasses of <code>Foo</code>.
            */
           public class ComponentHandler extends ComponentAdapter {
      +        /**
      +         * Constructs a {@code ComponentHandler}.
      +         */
      +        public ComponentHandler() {}
      +
               // NOTE: This class exists only for backward compatibility. All
               // its functionality has been moved into Handler. If you need to add
               // new functionality add it to the Handler, but make sure this
      @@ -2216,6 +2241,11 @@
            * Instantiate it only within subclasses of <code>Foo</code>.
            */
           public class FocusHandler implements FocusListener {
      +        /**
      +         * Constructs a {@code FocusHandler}.
      +         */
      +        public FocusHandler() {}
      +
               // NOTE: This class exists only for backward compatibility. All
               // its functionality has been moved into Handler. If you need to add
               // new functionality add it to the Handler, but make sure this
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSpinnerUI.java   2020-08-15 15:47:44.405308500 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSpinnerUI.java   2020-08-15 15:47:40.951500000 +0530
      @@ -80,6 +80,10 @@
            */
           private static final Dimension zeroSize = new Dimension(0, 0);
      
      +    /**
      +     * Constructs a {@code BasicSpinnerUI}.
      +     */
      +    public BasicSpinnerUI() {}
      
           /**
            * Returns a new instance of BasicSpinnerUI.  SpinnerListUI
      --- old/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSplitPaneUI.java 2020-08-15 15:48:03.072399000 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSplitPaneUI.java 2020-08-15 15:47:59.714963300 +0530
      @@ -286,6 +286,10 @@
           /** If true, setDividerLocation does nothing. */
           boolean             ignoreDividerLocationChange;
      
      +    /**
      +     * Constructs a {@code BasicSplitPaneUI}.
      +     */
      +    public BasicSplitPaneUI() {}
      
           /**
            * Creates a new instance of {@code BasicSplitPaneUI}.
      @@ -734,6 +738,11 @@
            */
           public class FocusHandler extends FocusAdapter
           {
      +        /**
      +         * Constructs a {@code FocusHandler}.
      +         */
      +        public FocusHandler() {}
      +
               // NOTE: This class exists only for backward compatibility. All
               // its functionality has been moved into Handler. If you need to add
               // new functionality add it to the Handler, but make sure this
      @@ -774,6 +783,11 @@
            */
           public class KeyboardDownRightHandler implements ActionListener
           {
      +        /**
      +         * Constructs a {@code KeyboardDownRightHandler}.
      +         */
      +        public KeyboardDownRightHandler() {}
      +
               public void actionPerformed(ActionEvent ev) {
                   if (dividerKeyboardResize) {
                       splitPane.setDividerLocation(getDividerLocation(splitPane) +
      @@ -792,6 +806,11 @@
            */
           public class KeyboardHomeHandler implements ActionListener
           {
      +        /**
      +         * Constructs a {@code KeyboardHomeHandler}.
      +         */
      +        public KeyboardHomeHandler() {}
      +
               public void actionPerformed(ActionEvent ev) {
                   if (dividerKeyboardResize) {
                       splitPane.setDividerLocation(0);
      @@ -809,6 +828,11 @@
            */
           public class KeyboardEndHandler implements ActionListener
           {
      +        /**
      +         * Constructs a {@code KeyboardEndHandler}.
      +         */
      +        public KeyboardEndHandler() {}
      +
               public void actionPerformed(ActionEvent ev) {
                   if (dividerKeyboardResize) {
                       Insets   insets = splitPane.getInsets();

            psadhukhan Prasanta Sadhukhan
            prr Philip Race
            Sergey Bylokhov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: