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

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

    XMLWordPrintable

Details

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

    Description

      Summary

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

      Problem

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

      Solution

      Add protected constructors to the public abstract classes and explicit no-arg constructors to public class

      Specification

      --- old/src/java.desktop/share/classes/javax/swing/plaf/ButtonUI.java   2020-08-12 22:09:48.900867200 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/ButtonUI.java   2020-08-12 22:09:46.368861700 +0530
      @@ -36,4 +36,8 @@
        * @author Jeff Dinkins
        */
       public abstract class ButtonUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected ButtonUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/ColorChooserUI.java 2020-08-12 22:10:03.013587700 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/ColorChooserUI.java 2020-08-12 22:10:00.546887300 +0530
      @@ -37,5 +37,8 @@
      
       public abstract class ColorChooserUI extends ComponentUI
       {
      -
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected ColorChooserUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/ComboBoxUI.java 2020-08-12 22:10:16.673615000 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/ComboBoxUI.java 2020-08-12 22:10:14.273384000 +0530
      @@ -36,6 +36,11 @@
       public abstract class ComboBoxUI extends ComponentUI {
      
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected ComboBoxUI() {}
      +
      +    /**
            * Set the visibility of the popup
            *
            * @param c a {@code JComboBox}
      --- old/src/java.desktop/share/classes/javax/swing/plaf/DesktopIconUI.java  2020-08-12 22:10:30.461344600 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/DesktopIconUI.java  2020-08-12 22:10:28.100683500 +0530
      @@ -32,4 +32,8 @@
        * @author David Kloba
        */
       public abstract class DesktopIconUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected DesktopIconUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/DesktopPaneUI.java  2020-08-12 22:10:44.026540300 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/DesktopPaneUI.java  2020-08-12 22:10:41.640191000 +0530
      @@ -32,4 +32,8 @@
        * @author David Kloba
        */
       public abstract class DesktopPaneUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected DesktopPaneUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/FileChooserUI.java  2020-08-12 22:10:57.531842200 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/FileChooserUI.java  2020-08-12 22:10:55.169376700 +0530
      @@ -39,6 +39,11 @@
       public abstract class FileChooserUI extends ComponentUI
       {
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected FileChooserUI() {}
      +
      +    /**
            * Returns an accept-all file filter.
            * @param fc the file chooser
            * @return an accept-all file filter
      --- old/src/java.desktop/share/classes/javax/swing/plaf/InternalFrameUI.java    2020-08-12 22:11:11.857373800 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/InternalFrameUI.java    2020-08-12 22:11:09.390778100 +0530
      @@ -31,4 +31,8 @@
        * @author David Kloba
        */
       public abstract class InternalFrameUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected InternalFrameUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/LabelUI.java    2020-08-12 22:11:25.728276500 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/LabelUI.java    2020-08-12 22:11:23.258546900 +0530
      @@ -31,4 +31,9 @@
        * @author Hans Muller
        */
       public abstract class LabelUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected LabelUI() {}
       }
      +
      --- old/src/java.desktop/share/classes/javax/swing/plaf/LayerUI.java    2020-08-12 22:11:39.737017700 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/LayerUI.java    2020-08-12 22:11:36.863306000 +0530
      @@ -66,6 +66,11 @@
                   new PropertyChangeSupport(this);
      
           /**
      +     * Constructs a {@code LayerUI}.
      +     */
      +    public LayerUI() {}
      +
      +    /**
            * Paints the specified component.
            * Subclasses should override this method and use
            * the specified {@code Graphics} object to
      --- old/src/java.desktop/share/classes/javax/swing/plaf/ListUI.java 2020-08-12 22:11:54.611544400 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/ListUI.java 2020-08-12 22:11:51.979139800 +0530
      @@ -39,6 +39,11 @@
       public abstract class ListUI extends ComponentUI
       {
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected ListUI() {}
      +
      +    /**
            * Returns the cell index in the specified {@code JList} closest to the
            * given location in the list's coordinate system. To determine if the
            * cell actually contains the specified location, compare the point against
      --- old/src/java.desktop/share/classes/javax/swing/plaf/MenuBarUI.java  2020-08-12 22:12:09.338185400 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/MenuBarUI.java  2020-08-12 22:12:06.750215400 +0530
      @@ -36,4 +36,9 @@
        * @author David Karlton
        */
      
      -public abstract class MenuBarUI extends ComponentUI { }
      +public abstract class MenuBarUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected MenuBarUI() {}
      +}
      --- old/src/java.desktop/share/classes/javax/swing/plaf/MenuItemUI.java 2020-08-12 22:12:24.576590600 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/MenuItemUI.java 2020-08-12 22:12:21.838225700 +0530
      @@ -35,4 +35,8 @@
        * @author Arnaud Weber
        */
       public abstract class MenuItemUI extends ButtonUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected MenuItemUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/OptionPaneUI.java   2020-08-12 22:12:39.160040800 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/OptionPaneUI.java   2020-08-12 22:12:36.624731500 +0530
      @@ -36,6 +36,11 @@
       public abstract class OptionPaneUI extends ComponentUI
       {
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected OptionPaneUI() {}
      +
      +    /**
            * Requests the component representing the default value to have
            * focus.
            *
      --- old/src/java.desktop/share/classes/javax/swing/plaf/PanelUI.java    2020-08-12 22:12:54.053591200 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/PanelUI.java    2020-08-12 22:12:51.411508200 +0530
      @@ -32,4 +32,8 @@
        * @author Steve Wilson
        */
       public abstract class PanelUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected PanelUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/PopupMenuUI.java    2020-08-12 22:13:11.416643200 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/PopupMenuUI.java    2020-08-12 22:13:08.931329400 +0530
      @@ -39,6 +39,11 @@
      
       public abstract class PopupMenuUI extends ComponentUI {
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected PopupMenuUI() {}
      +
      +    /**
            * Returns whether or not the given {@code MouseEvent} is the popup menu
            * trigger event for the platform
            *
      --- old/src/java.desktop/share/classes/javax/swing/plaf/ProgressBarUI.java  2020-08-12 22:13:25.694478900 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/ProgressBarUI.java  2020-08-12 22:13:23.175249700 +0530
      @@ -32,4 +32,8 @@
        * @author Rob Davis
        */
       public abstract class ProgressBarUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected ProgressBarUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/RootPaneUI.java 2020-08-12 22:13:46.086282600 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/RootPaneUI.java 2020-08-12 22:13:42.905969700 +0530
      @@ -32,4 +32,8 @@
        * @since 1.3
        */
       public abstract class RootPaneUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected RootPaneUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/ScrollBarUI.java    2020-08-12 22:14:05.895068600 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/ScrollBarUI.java    2020-08-12 22:14:02.708088600 +0530
      @@ -31,4 +31,8 @@
        * @author David Kloba
        */
       public abstract class ScrollBarUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected ScrollBarUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/ScrollPaneUI.java   2020-08-12 22:14:23.372974200 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/ScrollPaneUI.java   2020-08-12 22:14:20.727696000 +0530
      @@ -33,4 +33,8 @@
        */
      
       public abstract class ScrollPaneUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected ScrollPaneUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/SeparatorUI.java    2020-08-12 22:14:38.588331200 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/SeparatorUI.java    2020-08-12 22:14:36.114010800 +0530
      @@ -33,4 +33,8 @@
        */
      
       public abstract class SeparatorUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected SeparatorUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/SliderUI.java   2020-08-12 22:14:53.345389300 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/SliderUI.java   2020-08-12 22:14:50.713931900 +0530
      @@ -31,4 +31,8 @@
        * @author Hans Muller
        */
       public abstract class SliderUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected SliderUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/SpinnerUI.java  2020-08-12 22:15:08.358643300 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/SpinnerUI.java  2020-08-12 22:15:05.433697700 +0530
      @@ -33,4 +33,8 @@
        * @since 1.4
        */
       public abstract class SpinnerUI extends javax.swing.plaf.ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected SpinnerUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/SplitPaneUI.java    2020-08-12 22:15:25.724250500 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/SplitPaneUI.java    2020-08-12 22:15:23.154363600 +0530
      @@ -36,6 +36,11 @@
       public abstract class SplitPaneUI extends ComponentUI
       {
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected SplitPaneUI() {}
      +
      +    /**
            * Messaged to relayout the JSplitPane based on the preferred size
            * of the children components.
            *
      --- old/src/java.desktop/share/classes/javax/swing/plaf/TabbedPaneUI.java   2020-08-12 22:15:40.532491800 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/TabbedPaneUI.java   2020-08-12 22:15:38.058157300 +0530
      @@ -36,6 +36,11 @@
        */
       public abstract class TabbedPaneUI extends ComponentUI {
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected TabbedPaneUI() {}
      +
      +    /**
            * Returns the tab for the coordinate.
            * @param pane the pane
            * @param x the x coordinate
      --- old/src/java.desktop/share/classes/javax/swing/plaf/TableHeaderUI.java  2020-08-12 22:15:56.144397000 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/TableHeaderUI.java  2020-08-12 22:15:53.271026500 +0530
      @@ -31,4 +31,8 @@
        * @author Alan Chung
        */
       public abstract class TableHeaderUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected TableHeaderUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/TableUI.java    2020-08-12 22:16:12.799970000 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/TableUI.java    2020-08-12 22:16:09.716902600 +0530
      @@ -31,4 +31,8 @@
        * @author Alan Chung
        */
       public abstract class TableUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected TableUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/TextUI.java 2020-08-12 22:16:31.339453500 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/TextUI.java 2020-08-12 22:16:28.643715700 +0530
      @@ -38,6 +38,11 @@
       public abstract class TextUI extends ComponentUI
       {
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected TextUI() {}
      +
      +    /**
            * Converts the given location in the model to a place in
            * the view coordinate system.
            *
      --- old/src/java.desktop/share/classes/javax/swing/plaf/ToolBarUI.java  2020-08-12 22:16:47.728381400 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/ToolBarUI.java  2020-08-12 22:16:45.075892600 +0530
      @@ -35,4 +35,8 @@
        */
      
       public abstract class ToolBarUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected ToolBarUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/ToolTipUI.java  2020-08-12 22:17:02.549615600 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/ToolTipUI.java  2020-08-12 22:16:59.726694400 +0530
      @@ -31,4 +31,8 @@
        * @author Dave Moore
        */
       public abstract class ToolTipUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected ToolTipUI() {}
       }
      --- old/src/java.desktop/share/classes/javax/swing/plaf/TreeUI.java 2020-08-12 22:17:17.432522700 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/TreeUI.java 2020-08-12 22:17:14.954537600 +0530
      @@ -38,6 +38,11 @@
       public abstract class TreeUI extends ComponentUI
       {
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected TreeUI() {}
      +
      +    /**
            * Returns the Rectangle enclosing the label portion that the
            * last item in path will be drawn into.  Will return null if
            * any component in path is currently valid.
      --- old/src/java.desktop/share/classes/javax/swing/plaf/ViewportUI.java 2020-08-12 22:17:34.490939000 +0530
      +++ new/src/java.desktop/share/classes/javax/swing/plaf/ViewportUI.java 2020-08-12 22:17:31.787581200 +0530
      @@ -32,4 +32,8 @@
        * @author Rich Schiavi
        */
       public abstract class ViewportUI extends ComponentUI {
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    protected ViewportUI() {}
       }

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: