Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate some UI classes for nullness #86

Merged
merged 21 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
77f965b
Annotate JFileChooser for Nullness
jpschewe Sep 26, 2020
5249a7f
Annotate Default*CellRenderer classes for nullness
jpschewe Sep 26, 2020
52a0a41
Annotate UIDefaults, UIManager and DefaultLookup for nullness
jpschewe Sep 26, 2020
911237e
Fix typo in annotation
jpschewe Sep 26, 2020
af3b19d
Coorect my nullness annotations in Locale
jpschewe Sep 27, 2020
cfb07b5
Don't annotate LocaleObjectCache for nullness
jpschewe Sep 27, 2020
66d7185
Finish annotating JDialog for nullness
jpschewe Sep 27, 2020
0319b9b
Finish annotating JRootPane for nullness
jpschewe Sep 27, 2020
2776bed
Finish annotating JFrame for nullness
jpschewe Sep 27, 2020
f9a684f
Finish annotating JComponent for nullness
jpschewe Sep 27, 2020
ffa93e0
Finish annotating awt.Frame for nullness
jpschewe Sep 27, 2020
5170f0a
Finish annotating Dialog for nullness
jpschewe Sep 27, 2020
1c36cb6
Finished annotating Window for nullness
jpschewe Sep 27, 2020
1a06f1c
Finish annotating awt.Container
jpschewe Sep 27, 2020
0e18624
Finish annotating awt.Component for nullness
jpschewe Sep 27, 2020
c55095d
Merge ../jdk-branch-master into annotate-swing-part-1
mernst Sep 27, 2020
05e0d86
Fix annotation on getActionMap
jpschewe Sep 28, 2020
42c7d21
Allow add and setLayout to be called from a child class' constructor
jpschewe Sep 28, 2020
21b3155
Revert nullness annotations on awt.Window
jpschewe Sep 28, 2020
b468c02
Array can be null, but elements should not.
jpschewe Sep 29, 2020
740371d
Fix annotation on selectedFiles field
jpschewe Sep 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 40 additions & 38 deletions src/java.desktop/share/classes/java/awt/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.checkerframework.checker.guieffect.qual.SafeEffect;
import org.checkerframework.checker.guieffect.qual.UIType;
import org.checkerframework.checker.interning.qual.UsesObjectEquals;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.AnnotatedFor;

import java.applet.Applet;
Expand Down Expand Up @@ -218,7 +220,7 @@
* @author Arthur van Hoff
* @author Sami Shaio
*/
@AnnotatedFor({"guieffect", "interning"})
@AnnotatedFor({"guieffect", "interning", "nullness"})
public abstract @UsesObjectEquals @UIType class Component implements ImageObserver, MenuContainer,
Serializable
{
Expand All @@ -242,7 +244,7 @@
* for top-level components.
* @see #getParent
*/
transient Container parent;
transient @Nullable Container parent;

/**
* The {@code AppContext} of the component. Applets/Plugin may
Expand Down Expand Up @@ -290,7 +292,7 @@
* @see #getForeground
* @see #setForeground
*/
Color foreground;
@Nullable Color foreground;

/**
* The background color for this component.
Expand All @@ -300,7 +302,7 @@
* @see #getBackground
* @see #setBackground
*/
Color background;
@Nullable Color background;

/**
* The font used by this component.
Expand Down Expand Up @@ -410,7 +412,7 @@
* @see #setDropTarget
* @see #getDropTarget
*/
DropTarget dropTarget;
@MonotonicNonNull DropTarget dropTarget;

/**
* @serial
Expand Down Expand Up @@ -531,7 +533,7 @@ static class AWTTreeLock {}
*
* @serial
*/
Dimension prefSize;
@Nullable Dimension prefSize;

/**
* Whether or not setPreferredSize has been invoked with a non-null value.
Expand Down Expand Up @@ -1014,7 +1016,7 @@ void initializeFocusTraversalKeys() {
* Constructs a name for this component. Called by {@code getName}
* when the name is {@code null}.
*/
String constructComponentName() {
@Nullable String constructComponentName() {
return null; // For strict compliance with prior platform versions, a Component
// that doesn't set its name should return null from
// getName()
Expand Down Expand Up @@ -1058,22 +1060,22 @@ public void setName(String name) {
* @return the parent container of this component
* @since 1.0
*/
public Container getParent() {
public @Nullable Container getParent() {
return getParent_NoClientCode();
}

// NOTE: This method may be called by privileged threads.
// This functionality is implemented in a package-private method
// to insure that it cannot be overridden by client subclasses.
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
final Container getParent_NoClientCode() {
final @Nullable Container getParent_NoClientCode() {
return parent;
}

// This method is overridden in the Window class to return null,
// because the parent field of the Window object contains
// the owner of the window, not its parent.
Container getContainer() {
@Nullable Container getContainer() {
return getParent_NoClientCode();
}

Expand Down Expand Up @@ -1132,7 +1134,7 @@ public synchronized void setDropTarget(DropTarget dt) {
* @return the drop target
*/

public synchronized DropTarget getDropTarget() { return dropTarget; }
public synchronized @Nullable DropTarget getDropTarget() { return dropTarget; }

/**
* Gets the {@code GraphicsConfiguration} associated with this
Expand All @@ -1149,11 +1151,11 @@ public synchronized void setDropTarget(DropTarget dt) {
* {@code Component} or {@code null}
* @since 1.3
*/
public GraphicsConfiguration getGraphicsConfiguration() {
public @Nullable GraphicsConfiguration getGraphicsConfiguration() {
return getGraphicsConfiguration_NoClientCode();
}

final GraphicsConfiguration getGraphicsConfiguration_NoClientCode() {
final @Nullable GraphicsConfiguration getGraphicsConfiguration_NoClientCode() {
return graphicsConfig;
}

Expand Down Expand Up @@ -1374,7 +1376,7 @@ Point pointRelativeToComponent(Point absolute) {
* tree lock, as it is done in Component.getMousePosition() and
* Container.getMousePosition(boolean).
*/
Component findUnderMouseInWindow(PointerInfo pi) {
@Nullable Component findUnderMouseInWindow(PointerInfo pi) {
if (!isShowing()) {
return null;
}
Expand Down Expand Up @@ -1790,7 +1792,7 @@ public void hide() {
* @since 1.0
*/
@Transient
public Color getForeground() {
public @Nullable Color getForeground() {
Color foreground = this.foreground;
if (foreground != null) {
return foreground;
Expand All @@ -1808,7 +1810,7 @@ public Color getForeground() {
* @see #getForeground
* @since 1.0
*/
public void setForeground(Color c) {
public void setForeground(@Nullable Color c) {
Color oldColor = foreground;
ComponentPeer peer = this.peer;
foreground = c;
Expand Down Expand Up @@ -1845,7 +1847,7 @@ public boolean isForegroundSet() {
* @since 1.0
*/
@Transient
public Color getBackground() {
public @Nullable Color getBackground() {
Color background = this.background;
if (background != null) {
return background;
Expand All @@ -1867,7 +1869,7 @@ public Color getBackground() {
* @see #getBackground
* @since 1.0
*/
public void setBackground(Color c) {
public void setBackground(@Nullable Color c) {
Color oldColor = background;
ComponentPeer peer = this.peer;
background = c;
Expand Down Expand Up @@ -1903,15 +1905,15 @@ public boolean isBackgroundSet() {
* @since 1.0
*/
@Transient
public Font getFont() {
public @Nullable Font getFont() {
return getFont_NoClientCode();
}

// NOTE: This method may be called by privileged threads.
// This functionality is implemented in a package-private method
// to insure that it cannot be overridden by client subclasses.
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
final Font getFont_NoClientCode() {
final @Nullable Font getFont_NoClientCode() {
Font font = this.font;
if (font != null) {
return font;
Expand Down Expand Up @@ -2664,7 +2666,7 @@ public boolean isLightweight() {
* @see #isPreferredSizeSet
* @since 1.5
*/
public void setPreferredSize(Dimension preferredSize) {
public void setPreferredSize(@Nullable Dimension preferredSize) {
Dimension old;
// If the preferred size was set, use it as the old value, otherwise
// use null to indicate we didn't previously have a set preferred
Expand Down Expand Up @@ -2740,7 +2742,7 @@ public Dimension preferredSize() {
* @see #isMinimumSizeSet
* @since 1.5
*/
public void setMinimumSize(Dimension minimumSize) {
public void setMinimumSize(@Nullable Dimension minimumSize) {
Dimension old;
// If the minimum size was set, use it as the old value, otherwise
// use null to indicate we didn't previously have a set minimum
Expand Down Expand Up @@ -2814,7 +2816,7 @@ public Dimension minimumSize() {
* @see #isMaximumSizeSet
* @since 1.5
*/
public void setMaximumSize(Dimension maximumSize) {
public void setMaximumSize(@Nullable Dimension maximumSize) {
// If the maximum size was set, use it as the old value, otherwise
// use null to indicate we didn't previously have a set maximum
// size.
Expand Down Expand Up @@ -3108,7 +3110,7 @@ final void revalidateSynchronously() {
* @see #paint
* @since 1.0
*/
public Graphics getGraphics() {
public @Nullable Graphics getGraphics() {
if (peer instanceof LightweightPeer) {
// This is for a lightweight component, need to
// translate coordinate spaces and clip relative
Expand All @@ -3130,7 +3132,7 @@ public Graphics getGraphics() {
}
}

final Graphics getGraphics_NoClientCode() {
final @Nullable Graphics getGraphics_NoClientCode() {
ComponentPeer peer = this.peer;
if (peer instanceof LightweightPeer) {
// This is for a lightweight component, need to
Expand Down Expand Up @@ -3211,7 +3213,7 @@ public FontMetrics getFontMetrics(Font font) {
* @see Cursor
* @since 1.1
*/
public void setCursor(Cursor cursor) {
public void setCursor(@Nullable Cursor cursor) {
this.cursor = cursor;
updateCursorImmediately();
}
Expand Down Expand Up @@ -3663,7 +3665,7 @@ public Image createImage(ImageProducer producer) {
* @see GraphicsEnvironment#isHeadless
* @since 1.0
*/
public Image createImage(int width, int height) {
public @Nullable Image createImage(int width, int height) {
ComponentPeer peer = this.peer;
if (peer instanceof LightweightPeer) {
if (parent != null) { return parent.createImage(width, height); }
Expand All @@ -3688,7 +3690,7 @@ public Image createImage(int width, int height) {
* @see GraphicsEnvironment#isHeadless
* @since 1.4
*/
public VolatileImage createVolatileImage(int width, int height) {
public @Nullable VolatileImage createVolatileImage(int width, int height) {
ComponentPeer peer = this.peer;
if (peer instanceof LightweightPeer) {
if (parent != null) {
Expand Down Expand Up @@ -3719,7 +3721,7 @@ public VolatileImage createVolatileImage(int width, int height) {
* @see java.awt.image.VolatileImage
* @since 1.4
*/
public VolatileImage createVolatileImage(int width, int height,
public @Nullable VolatileImage createVolatileImage(int width, int height,
ImageCapabilities caps)
throws AWTException {
// REMIND : check caps
Expand Down Expand Up @@ -4798,7 +4800,7 @@ public boolean contains(Point p) {
* @see #contains(int, int)
* @since 1.0
*/
public Component getComponentAt(int x, int y) {
public @Nullable Component getComponentAt(int x, int y) {
return locate(x, y);
}

Expand All @@ -4814,7 +4816,7 @@ public Component getComponentAt(int x, int y) {
* replaced by getComponentAt(int, int).
*/
@Deprecated
public Component locate(int x, int y) {
public @Nullable Component locate(int x, int y) {
return contains(x, y) ? this : null;
}

Expand All @@ -4826,7 +4828,7 @@ public Component locate(int x, int y) {
* @see java.awt.Component#contains
* @since 1.1
*/
public Component getComponentAt(Point p) {
public @Nullable Component getComponentAt(Point p) {
return getComponentAt(p.x, p.y);
}

Expand Down Expand Up @@ -6154,7 +6156,7 @@ public InputMethodRequests getInputMethodRequests() {
* {@code null} if no context can be determined
* @since 1.2
*/
public InputContext getInputContext() {
public @Nullable InputContext getInputContext() {
Container parent = this.parent;
if (parent == null) {
return null;
Expand Down Expand Up @@ -8133,7 +8135,7 @@ static synchronized void setRequestFocusController(RequestFocusController reques
* @see Container#isFocusCycleRoot()
* @since 1.4
*/
public Container getFocusCycleRootAncestor() {
public @Nullable Container getFocusCycleRootAncestor() {
Container rootAncestor = this.parent;
while (rootAncestor != null && !rootAncestor.isFocusCycleRoot()) {
rootAncestor = rootAncestor.parent;
Expand Down Expand Up @@ -8726,7 +8728,7 @@ public PropertyChangeListener[] getPropertyChangeListeners(String propertyName)
* @param newValue the property's new value
*/
protected void firePropertyChange(String propertyName,
Object oldValue, Object newValue) {
@Nullable Object oldValue, @Nullable Object newValue) {
PropertyChangeSupport changeSupport;
synchronized (getObjectLock()) {
changeSupport = this.changeSupport;
Expand Down Expand Up @@ -9279,7 +9281,7 @@ final void relocateComponent() {
* @return Window ancestor of the component or component by itself if it is Window;
* null, if component is not a part of window hierarchy
*/
Window getContainingWindow() {
@Nullable Window getContainingWindow() {
return SunToolkit.getContainingWindow(this);
}

Expand Down Expand Up @@ -10170,7 +10172,7 @@ final int getSiblingIndexAbove() {
return nextAbove < 0 ? -1 : nextAbove;
}

final ComponentPeer getHWPeerAboveMe() {
final @Nullable ComponentPeer getHWPeerAboveMe() {
checkTreeLock();

Container cont = getContainer();
Expand Down Expand Up @@ -10486,7 +10488,7 @@ final boolean isMixingNeeded() {
* @param shape the new 'mixing-cutout' shape
* @since 9
*/
public void setMixingCutoutShape(Shape shape) {
public void setMixingCutoutShape(@Nullable Shape shape) {
Region region = shape == null ? null : Region.getInstance(shape, null);

synchronized (getTreeLock()) {
Expand Down
Loading