Skip to content

Commit

Permalink
8286663: Resolve IDE warnings in WTrayIconPeer and SystemTray
Browse files Browse the repository at this point in the history
Reviewed-by: prr, serb, honkar
  • Loading branch information
aivanov-jdk committed Jun 8, 2022
1 parent b021d37 commit a9b9831
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

5 comments on commit a9b9831

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on a9b9831 Sep 26, 2022

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on a9b9831 Sep 26, 2022

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch GoeLin-backport-a9b9831f in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit a9b9831f from the openjdk/jdk repository.

The commit being backported was authored by Alexey Ivanov on 8 Jun 2022 and was reviewed by Phil Race, Sergey Bylokhov and Harshitha Onkar.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-a9b9831f:GoeLin-backport-a9b9831f
$ git checkout GoeLin-backport-a9b9831f
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-a9b9831f

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on a9b9831 Oct 11, 2022

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on a9b9831 Oct 11, 2022

Choose a reason for hiding this comment

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

@GoeLin Could not automatically backport a9b9831f to openjdk/jdk11u-dev due to conflicts in the following files:

  • src/java.desktop/share/classes/java/awt/SystemTray.java
  • src/java.desktop/windows/classes/sun/awt/windows/WTrayIconPeer.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b GoeLin-backport-a9b9831f

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk a9b9831f2a88ed3b7701d402b167a096b94aeb98

# Backport the commit
$ git cherry-pick --no-commit a9b9831f2a88ed3b7701d402b167a096b94aeb98
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport a9b9831f2a88ed3b7701d402b167a096b94aeb98'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport a9b9831f2a88ed3b7701d402b167a096b94aeb98.

Please sign in to comment.