Skip to content

Commit 91151bc

Browse files
committed
Invoker null check
1 parent c78ede2 commit 91151bc

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/java.desktop/share/classes/javax/swing/JPopupMenu.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -952,20 +952,21 @@ && isVisible()) {
952952
@BeanProperty(bound = false, expert = true, description
953953
= "The invoking component for the popup menu")
954954
public void setInvoker(Component invoker) {
955-
if (invoker != null) {
956-
Component oldInvoker = this.invoker;
957-
this.invoker = invoker;
955+
Component oldInvoker = this.invoker;
956+
this.invoker = invoker;
958957

959-
if ((oldInvoker != this.invoker) && (ui != null)) {
960-
ui.uninstallUI(this);
961-
if (oldInvoker != null) {
962-
oldInvoker.removePropertyChangeListener("ancestor", propListener);
963-
}
958+
if ((oldInvoker != this.invoker) && (ui != null)) {
959+
ui.uninstallUI(this);
960+
if (oldInvoker != null) {
961+
oldInvoker.removePropertyChangeListener("ancestor", propListener);
962+
}
963+
if (invoker != null) {
964964
invoker.addPropertyChangeListener("ancestor", propListener);
965-
ui.installUI(this);
966965
}
967-
invalidate();
966+
ui.installUI(this);
968967
}
968+
invalidate();
969+
969970
}
970971

971972
/**

test/jdk/javax/swing/JPopupMenu/TestPopupInvoker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
7373
@Override
7474
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
7575
popupHidden.countDown();
76+
popupMenu.setInvoker(null);
7677
}
7778

7879
@Override
@@ -108,7 +109,6 @@ public static void main(String[] args) throws Exception {
108109
}
109110
} finally {
110111
SwingUtilities.invokeAndWait(() -> {
111-
popupMenu.setInvoker(null);
112112
if (frame != null) {
113113
frame.dispose();
114114
}

0 commit comments

Comments
 (0)