Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8286663: Resolve IDE warnings in WTrayIconPeer and SystemTray
Backport-of: a9b9831f2a88ed3b7701d402b167a096b94aeb98
  • Loading branch information
GoeLin committed Sep 28, 2022
1 parent 79288de commit ad9e9f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
26 changes: 10 additions & 16 deletions src/java.desktop/share/classes/java/awt/SystemTray.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -131,15 +131,7 @@ public class SystemTray {
private static final TrayIcon[] EMPTY_TRAY_ARRAY = new TrayIcon[0];

static {
AWTAccessor.setSystemTrayAccessor(
new AWTAccessor.SystemTrayAccessor() {
public void firePropertyChange(SystemTray tray,
String propertyName,
Object oldValue,
Object newValue) {
tray.firePropertyChange(propertyName, oldValue, newValue);
}
});
AWTAccessor.setSystemTrayAccessor(SystemTray::firePropertyChange);
}

/**
Expand Down Expand Up @@ -257,15 +249,16 @@ public void add(TrayIcon trayIcon) throws AWTException {
if (trayIcon == null) {
throw new NullPointerException("adding null TrayIcon");
}
TrayIcon[] oldArray = null, newArray = null;
Vector<TrayIcon> icons = null;
TrayIcon[] oldArray;
TrayIcon[] newArray;
Vector<TrayIcon> icons;
synchronized (this) {
oldArray = systemTray.getTrayIcons();
@SuppressWarnings("unchecked")
Vector<TrayIcon> tmp = (Vector<TrayIcon>)AppContext.getAppContext().get(TrayIcon.class);
icons = tmp;
if (icons == null) {
icons = new Vector<TrayIcon>(3);
icons = new Vector<>(3);
AppContext.getAppContext().put(TrayIcon.class, icons);

} else if (icons.contains(trayIcon)) {
Expand Down Expand Up @@ -305,7 +298,8 @@ public void remove(TrayIcon trayIcon) {
if (trayIcon == null) {
return;
}
TrayIcon[] oldArray = null, newArray = null;
TrayIcon[] oldArray;
TrayIcon[] newArray;
synchronized (this) {
oldArray = systemTray.getTrayIcons();
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -343,7 +337,7 @@ public TrayIcon[] getTrayIcons() {
@SuppressWarnings("unchecked")
Vector<TrayIcon> icons = (Vector<TrayIcon>)AppContext.getAppContext().get(TrayIcon.class);
if (icons != null) {
return icons.toArray(new TrayIcon[icons.size()]);
return icons.toArray(EMPTY_TRAY_ARRAY);
}
return EMPTY_TRAY_ARRAY;
}
Expand Down Expand Up @@ -475,7 +469,7 @@ public synchronized PropertyChangeListener[] getPropertyChangeListeners(String p
private void firePropertyChange(String propertyName,
Object oldValue, Object newValue)
{
if (oldValue != null && newValue != null && oldValue.equals(newValue)) {
if (oldValue != null && oldValue.equals(newValue)) {
return;
}
getCurrentChangeSupport().firePropertyChange(propertyName, oldValue, newValue);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,17 +25,20 @@

package sun.awt.windows;

import java.awt.Graphics2D;
import java.awt.AWTEvent;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.PopupMenu;
import java.awt.Image;
import java.awt.Point;
import java.awt.PopupMenu;
import java.awt.TrayIcon;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.ImageObserver;
import java.awt.image.Raster;
import java.awt.peer.TrayIconPeer;
import java.awt.image.*;

import sun.awt.AWTAccessor;
import sun.awt.SunToolkit;
Expand All @@ -49,14 +52,11 @@ final class WTrayIconPeer extends WObjectPeer implements TrayIconPeer {

IconObserver observer = new IconObserver();
boolean firstUpdate = true;
Frame popupParent = new Frame("PopupMessageWindow");
final Frame popupParent = new Frame("PopupMessageWindow");
PopupMenu popup;

@Override
protected void disposeImpl() {
if (popupParent != null) {
popupParent.dispose();
}
popupParent.dispose();
_dispose();
WToolkit.targetDisposedPeer(target, this);
Expand Down

1 comment on commit ad9e9f2

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.