8250853: Address reliance on default constructors in the javax.swing APIs

Reviewed-by: serb
This commit is contained in:
Prasanta Sadhukhan 2020-08-26 17:20:05 +05:30
parent fa31c0de68
commit 4b8ea58b76
44 changed files with 294 additions and 2 deletions

@ -235,6 +235,11 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl
private boolean hideActionText = false;
/**
* Constructor for subclasses to call.
*/
protected AbstractButton() {}
/**
* Sets the <code>hideActionText</code> property, which determines
* whether the button displays text from the <code>Action</code>.

@ -62,6 +62,11 @@ public abstract class AbstractCellEditor implements CellEditor, Serializable {
*/
protected transient ChangeEvent changeEvent = null;
/**
* Constructor for subclasses to call.
*/
protected AbstractCellEditor() {}
// Force this to be implemented.
// public Object getCellEditorValue()

@ -55,6 +55,10 @@ public abstract class AbstractListModel<E> implements ListModel<E>, Serializable
*/
protected EventListenerList listenerList = new EventListenerList();
/**
* Constructor for subclasses to call.
*/
protected AbstractListModel() {}
/**
* Adds a listener to the list that's notified each time a change

@ -64,6 +64,10 @@ public abstract class AbstractSpinnerModel implements SpinnerModel, Serializable
*/
protected EventListenerList listenerList = new EventListenerList();
/**
* Constructor for subclasses to call.
*/
protected AbstractSpinnerModel() {}
/**
* Adds a ChangeListener to the model's listener list. The

@ -76,6 +76,11 @@ public class DefaultDesktopManager implements DesktopManager, java.io.Serializab
*/
private transient boolean didDrag;
/**
* Constructs a {@code DefaultDesktopManager}.
*/
public DefaultDesktopManager() {}
/** Normally this method will not be called. If it is, it
* tries to determine the appropriate parent from the desktopIcon of the frame.
* Will remove the desktopIcon from its parent if it successfully adds the frame.

@ -351,5 +351,9 @@ public class DefaultListCellRenderer extends JLabel
public static class UIResource extends DefaultListCellRenderer
implements javax.swing.plaf.UIResource
{
/**
* Constructs a {@code UIResource}.
*/
public UIResource() {}
}
}

@ -57,6 +57,11 @@ public class DefaultListModel<E> extends AbstractListModel<E>
{
private Vector<E> delegate = new Vector<E>();
/**
* Constructs a {@code DefaultListModel}.
*/
public DefaultListModel() {}
/**
* Returns the number of components in this list.
* <p>

@ -78,6 +78,11 @@ public class DefaultListSelectionModel implements ListSelectionModel, Cloneable,
*/
protected boolean leadAnchorNotificationEnabled = true;
/**
* Constructs a {@code DefaultListSelectionModel}.
*/
public DefaultListSelectionModel() {}
/** {@inheritDoc} */
public int getMinSelectionIndex() { return isSelectionEmpty() ? -1 : minIndex; }

@ -58,6 +58,11 @@ Serializable {
private int index = -1;
/**
* Constructs a {@code DefaultSingleSelectionModel}.
*/
public DefaultSingleSelectionModel() {}
/**
* {@inheritDoc}
*/

@ -64,6 +64,11 @@ public abstract class FocusManager extends DefaultKeyboardFocusManager {
private static boolean enabled = true;
/**
* Constructor for subclasses to call.
*/
protected FocusManager() {}
/**
* Returns the current <code>KeyboardFocusManager</code> instance
* for the calling thread's context.

@ -98,6 +98,11 @@ import java.util.*;
*/
public abstract class InputVerifier {
/**
* Constructor for subclasses to call.
*/
protected InputVerifier() {}
/**
* Checks whether the JComponent's input is valid. This method should
* have no side effects. It returns a boolean indicating the status

@ -42,6 +42,10 @@ import java.awt.FocusTraversalPolicy;
public abstract class InternalFrameFocusTraversalPolicy
extends FocusTraversalPolicy
{
/**
* Constructor for subclasses to call.
*/
protected InternalFrameFocusTraversalPolicy() {}
/**
* Returns the Component that should receive the focus when a

@ -869,6 +869,11 @@ public class JFormattedTextField extends JTextField {
* @since 1.4
*/
public abstract static class AbstractFormatterFactory {
/**
* Constructor for subclasses to call.
*/
protected AbstractFormatterFactory() {}
/**
* Returns an <code>AbstractFormatter</code> that can handle formatting
* of the passed in <code>JFormattedTextField</code>.
@ -914,6 +919,11 @@ public class JFormattedTextField extends JTextField {
public abstract static class AbstractFormatter implements Serializable {
private JFormattedTextField ftf;
/**
* Constructor for subclasses to call.
*/
protected AbstractFormatter() {}
/**
* Installs the <code>AbstractFormatter</code> onto a particular
* <code>JFormattedTextField</code>.

@ -151,6 +151,10 @@ import java.util.StringTokenizer;
*/
public abstract class LookAndFeel
{
/**
* Constructor for subclasses to call.
*/
protected LookAndFeel() {}
/**
* Convenience method for setting a component's foreground

@ -51,6 +51,11 @@ public class MenuSelectionManager {
private static final StringBuilder MENU_SELECTION_MANAGER_KEY =
new StringBuilder("javax.swing.MenuSelectionManager");
/**
* Constructs a {@code MenuSelectionManager}.
*/
public MenuSelectionManager() {}
/**
* Returns the default menu selection manager.
*

@ -115,6 +115,10 @@ public class PopupFactory {
*/
private int popupType = LIGHT_WEIGHT_POPUP;
/**
* Constructs a {@code PopupFactory}.
*/
public PopupFactory() {}
/**
* Sets the <code>PopupFactory</code> that will be used to obtain

@ -128,6 +128,11 @@ public abstract class RowFilter<M,I> {
NOT_EQUAL
}
/**
* Constructor for subclasses to call.
*/
protected RowFilter() {}
/**
* Throws an IllegalArgumentException if any of the values in
* columns are {@literal <} 0.

@ -154,6 +154,10 @@ public class ScrollPaneLayout
*/
protected int hsbPolicy = HORIZONTAL_SCROLLBAR_AS_NEEDED;
/**
* Constructs a {@code ScrollPaneLayout}.
*/
public ScrollPaneLayout() {}
/**
* This method is invoked after the ScrollPaneLayout is set as the
@ -1116,5 +1120,10 @@ public class ScrollPaneLayout
/**
* The UI resource version of <code>ScrollPaneLayout</code>.
*/
public static class UIResource extends ScrollPaneLayout implements javax.swing.plaf.UIResource {}
public static class UIResource extends ScrollPaneLayout implements javax.swing.plaf.UIResource {
/**
* Constructs a {@code UIResource}.
*/
public UIResource() {}
}
}

@ -234,6 +234,11 @@ public class UIManager implements Serializable
*/
private static final Object classLock = new Object();
/**
* Constructs a {@code UIManager}.
*/
public UIManager() {}
/**
* Return the <code>LAFState</code> object, lazily create one if necessary.
* All access to the <code>LAFState</code> fields is done via this method,

@ -63,6 +63,11 @@ public class ViewportLayout implements LayoutManager, Serializable
// Single instance used by JViewport.
static ViewportLayout SHARED_INSTANCE = new ViewportLayout();
/**
* Constructs a {@code ViewportLayout}.
*/
public ViewportLayout() {}
/**
* Adds the specified component to the layout. Not used by this class.
* @param name the name of the component

@ -49,6 +49,11 @@ import java.io.Serializable;
@SuppressWarnings("serial")
public abstract class AbstractBorder implements Border, Serializable
{
/**
* Constructor for subclasses to call.
*/
protected AbstractBorder() {}
/**
* This default implementation does no painting.
* @param c the component for which this border is being painted

@ -73,6 +73,11 @@ public abstract class AbstractColorChooserPanel extends JPanel {
*/
private JColorChooser chooser;
/**
* Constructor for subclasses to call.
*/
protected AbstractColorChooserPanel() {}
/**
* Invoked automatically when the model's state changes.
* It is also called by <code>installChooserPanel</code> to allow

@ -104,6 +104,11 @@ public class EventListenerList implements Serializable {
/** The list of ListenerType - Listener pairs */
protected transient volatile Object[] listenerList = NULL_ARRAY;
/**
* Constructs a {@code EventListenerList}.
*/
public EventListenerList() {}
/**
* Passes back the event listener list as an array
* of ListenerType-listener pairs. Note that for

@ -41,6 +41,11 @@ package javax.swing.event;
* @author Thomas Ball
*/
public abstract class InternalFrameAdapter implements InternalFrameListener {
/**
* Constructor for subclasses to call.
*/
protected InternalFrameAdapter() {}
/**
* Invoked when an internal frame has been opened.
*/

@ -39,4 +39,8 @@ import java.awt.event.MouseAdapter;
*/
public abstract class MouseInputAdapter extends MouseAdapter
implements MouseInputListener {
/**
* Constructor for subclasses to call.
*/
protected MouseInputAdapter() {}
}

@ -49,6 +49,11 @@ import java.io.File;
* @author Jeff Dinkins
*/
public abstract class FileFilter {
/**
* Constructor for subclasses to call.
*/
protected FileFilter() {}
/**
* Whether the given file is accepted by this filter.
*

@ -66,6 +66,11 @@ import javax.swing.*;
*
*/
public abstract class FileView {
/**
* Constructor for subclasses to call.
*/
protected FileView() {}
/**
* The name of the file. Normally this would be simply
* <code>f.getName()</code>.

@ -67,6 +67,11 @@ public abstract class AbstractTableModel implements TableModel, Serializable
/** List of listeners */
protected EventListenerList listenerList = new EventListenerList();
/**
* Constructor for subclasses to call.
*/
protected AbstractTableModel() {}
//
// Default Implementation of the Interface
//

@ -400,6 +400,10 @@ public class DefaultTableCellRenderer extends JLabel
public static class UIResource extends DefaultTableCellRenderer
implements javax.swing.plaf.UIResource
{
/**
* Constructs a {@code UIResource}.
*/
public UIResource() {}
}
}

@ -32,6 +32,11 @@ package javax.swing.table;
* @since 1.6
*/
public abstract class TableStringConverter {
/**
* Constructor for subclasses to call.
*/
protected TableStringConverter() {}
/**
* Returns the string representation of the value at the specified
* location.

@ -37,6 +37,9 @@ import javax.swing.plaf.basic.BasicTextUI;
*/
@Deprecated
public abstract class DefaultTextUI extends BasicTextUI {
/**
* Constructor for subclasses to call.
*/
protected DefaultTextUI() {}
}

@ -60,6 +60,11 @@ package javax.swing.text;
* @since 1.4
*/
public class DocumentFilter {
/**
* Constructs a {@code DocumentFilter}.
*/
public DocumentFilter() {}
/**
* Invoked prior to removal of the specified region in the
* specified Document. Subclasses that want to conditionally allow
@ -130,6 +135,11 @@ public class DocumentFilter {
* @since 1.4
*/
public abstract static class FilterBypass {
/**
* Constructor for subclasses to call.
*/
protected FilterBypass() {}
/**
* Returns the Document the mutation is occurring on.
*

@ -341,6 +341,11 @@ public abstract class FlowView extends BoxView {
* @since 1.3
*/
public static class FlowStrategy {
/**
* Constructs a {@code FlowStrategy}.
*/
public FlowStrategy() {}
Position damageStart = null;
Vector<View> viewBuffer;

@ -1139,6 +1139,11 @@ public class GlyphView extends View implements TabableView, Cloneable {
*/
public abstract static class GlyphPainter {
/**
* Constructor for subclasses to call.
*/
protected GlyphPainter() {}
/**
* Determine the span the glyphs given a start location
* (for tab expansion).

@ -34,6 +34,11 @@ import java.awt.Shape;
* @see Highlighter
*/
public abstract class LayeredHighlighter implements Highlighter {
/**
* Constructor for subclasses to call.
*/
protected LayeredHighlighter() {}
/**
* When leaf Views (such as LabelView) are rendering they should
* call into this method. If a highlight is in the given region it will
@ -56,6 +61,11 @@ public abstract class LayeredHighlighter implements Highlighter {
* Layered highlight renderer.
*/
public abstract static class LayerPainter implements Highlighter.HighlightPainter {
/**
* Constructor for subclasses to call.
*/
protected LayerPainter() {}
/**
* @return a shape
* @param g Graphics used to draw

@ -49,6 +49,11 @@ import java.awt.Shape;
* @since 1.4
*/
public class NavigationFilter {
/**
* Constructs a {@code NavigationFilter}.
*/
public NavigationFilter() {}
/**
* Invoked prior to the Caret setting the dot. The default implementation
* calls directly into the <code>FilterBypass</code> with the passed
@ -121,6 +126,11 @@ public class NavigationFilter {
* @since 1.4
*/
public abstract static class FilterBypass {
/**
* Constructor for subclasses to call.
*/
protected FilterBypass() {}
/**
* Returns the Caret that is changing.
*

@ -49,6 +49,11 @@ import static sun.swing.SwingUtilities2.getFontCharsWidth;
* @author Timothy Prinzing
*/
public class Utilities {
/**
* Constructs a {@code Utilities}.
*/
public Utilities() {}
/**
* If <code>view</code>'s container is a <code>JComponent</code> it
* is returned, after casting.

@ -40,6 +40,11 @@ import javax.swing.text.StyleContext;
*/
public class HTML {
/**
* Constructs a {@code HTML}.
*/
public HTML() {}
/**
* Typesafe enumeration for an HTML tag. Although the
* set of HTML tags is a closed set, we have left the

@ -1888,6 +1888,11 @@ public class HTMLDocument extends DefaultStyledDocument {
*/
public abstract static class Iterator {
/**
* Constructor for subclasses to call.
*/
protected Iterator() {}
/**
* Return the attributes for this tag.
* @return the <code>AttributeSet</code> for this tag, or
@ -2966,6 +2971,10 @@ public class HTMLDocument extends DefaultStyledDocument {
* switch statement.
*/
public class TagAction {
/**
* Constructs a {@code TagAction}.
*/
public TagAction() {}
/**
* Called when a start tag is seen for the
@ -3000,6 +3009,10 @@ public class HTMLDocument extends DefaultStyledDocument {
* Action assigned by default to handle the Block task of the reader.
*/
public class BlockAction extends TagAction {
/**
* Constructs a {@code BlockAction}.
*/
public BlockAction() {}
public void start(HTML.Tag t, MutableAttributeSet attr) {
blockOpen(t, attr);
@ -3041,6 +3054,11 @@ public class HTMLDocument extends DefaultStyledDocument {
*/
public class ParagraphAction extends BlockAction {
/**
* Constructs a {@code ParagraphAction}.
*/
public ParagraphAction() {}
public void start(HTML.Tag t, MutableAttributeSet a) {
super.start(t, a);
inParagraph = true;
@ -3056,6 +3074,10 @@ public class HTMLDocument extends DefaultStyledDocument {
* Action assigned by default to handle the Special task of the reader.
*/
public class SpecialAction extends TagAction {
/**
* Constructs a {@code SpecialAction}.
*/
public SpecialAction() {}
public void start(HTML.Tag t, MutableAttributeSet a) {
addSpecialElement(t, a);
@ -3068,6 +3090,11 @@ public class HTMLDocument extends DefaultStyledDocument {
*/
public class IsindexAction extends TagAction {
/**
* Constructs a {@code IsindexAction}.
*/
public IsindexAction() {}
public void start(HTML.Tag t, MutableAttributeSet a) {
blockOpen(HTML.Tag.IMPLIED, new SimpleAttributeSet());
addSpecialElement(t, a);
@ -3082,6 +3109,11 @@ public class HTMLDocument extends DefaultStyledDocument {
*/
public class HiddenAction extends TagAction {
/**
* Constructs a {@code HiddenAction}.
*/
public HiddenAction() {}
public void start(HTML.Tag t, MutableAttributeSet a) {
addSpecialElement(t, a);
}
@ -3311,6 +3343,11 @@ public class HTMLDocument extends DefaultStyledDocument {
*/
public class PreAction extends BlockAction {
/**
* Constructs a {@code PreAction}.
*/
public PreAction() {}
public void start(HTML.Tag t, MutableAttributeSet attr) {
inPre = true;
blockOpen(t, attr);
@ -3332,6 +3369,11 @@ public class HTMLDocument extends DefaultStyledDocument {
*/
public class CharacterAction extends TagAction {
/**
* Constructs a {@code CharacterAction}.
*/
public CharacterAction() {}
public void start(HTML.Tag t, MutableAttributeSet attr) {
pushCharacterStyle();
if (!foundInsertTag) {
@ -3584,6 +3626,11 @@ public class HTMLDocument extends DefaultStyledDocument {
*/
public class FormAction extends SpecialAction {
/**
* Constructs a {@code FormAction}.
*/
public FormAction() {}
public void start(HTML.Tag t, MutableAttributeSet attr) {
if (t == HTML.Tag.INPUT) {
String type = (String)

@ -674,6 +674,11 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
*/
private int curOffset;
/**
* Constructs a {@code LinkController}.
*/
public LinkController() {}
/**
* Called for a mouse click event.
* If the component is read-only (ie a browser) then
@ -989,6 +994,11 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
* implementation provided by this editor kit.
*/
public abstract static class Parser {
/**
* Constructor for subclasses to call.
*/
protected Parser() {}
/**
* Parse the given stream and drive the given callback
* with the results of the parse. This method should
@ -1016,6 +1026,11 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
* @see javax.swing.text.html.parser.DocumentParser
*/
public static class ParserCallback {
/**
* Constructs a {@code ParserCallback}.
*/
public ParserCallback() {}
/**
* This is passed as an attribute in the attributeset to indicate
* the element is implied eg, the string '&lt;&gt;foo&lt;\t&gt;'
@ -1236,6 +1251,10 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
* </table>
*/
public static class HTMLFactory implements ViewFactory {
/**
* Constructs a {@code HTMLFactory}.
*/
public HTMLFactory() {}
/**
* Creates a view from an element.

@ -64,6 +64,10 @@ public abstract class AbstractLayoutCache implements RowMapper {
*/
protected int rowHeight;
/**
* Constructor for subclasses to call.
*/
protected AbstractLayoutCache() {}
/**
* Sets the renderer that is responsible for drawing nodes in the tree
@ -510,6 +514,11 @@ public abstract class AbstractLayoutCache implements RowMapper {
* and x origin of a particular node.
*/
public abstract static class NodeDimensions {
/**
* Constructor for subclasses to call.
*/
protected NodeDimensions() {}
/**
* Returns, by reference in bounds, the size and x origin to
* place value at. The calling method is responsible for determining

@ -40,4 +40,8 @@ package javax.swing.undo;
*/
@SuppressWarnings("serial") // Same-version serialization only
public class CannotRedoException extends RuntimeException {
/**
* Constructs a {@code CannotRedoException}.
*/
public CannotRedoException() {}
}

@ -41,4 +41,8 @@ package javax.swing.undo;
*/
@SuppressWarnings("serial") // Same-version serialization only
public class CannotUndoException extends RuntimeException {
/**
* Constructs a {@code CannotUndoException}.
*/
public CannotUndoException() {}
}

@ -41,6 +41,11 @@ import sun.awt.UngrabEvent;
*/
public class SwingInterOpUtils {
/**
* Constructs a {@code SwingInterOpUtils}.
*/
public SwingInterOpUtils() {}
public static void postEvent(Object target, java.awt.AWTEvent e) {
AppContext context = SunToolkit.targetToAppContext(target);
if (context != null) {