Skip to content

Commit 780cc4d

Browse files
author
duke
committed
Automatic merge of jdk:master into master
2 parents c276a38 + 3a3ea7e commit 780cc4d

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

src/java.desktop/share/classes/java/awt/Toolkit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ public void addAWTEventListener(AWTEventListener listener, long eventMask) {
17351735
public void removeAWTEventListener(AWTEventListener listener) {
17361736
AWTEventListener localL = deProxyAWTEventListener(listener);
17371737

1738-
if (listener == null) {
1738+
if (localL == null) {
17391739
return;
17401740
}
17411741

test/jdk/java/awt/Toolkit/AWTEventListenerProxyTest/AWTEventListenerProxyTest.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/*
2525
@test
26-
@bug 4290704
26+
@bug 4290704 8357598
2727
@summary Test use of AWTEventListenerProxyTest class
2828
*/
2929

@@ -38,33 +38,31 @@ public class AWTEventListenerProxyTest {
3838
public static void main(String[] args) throws Exception {
3939
EventQueue.invokeAndWait(() -> {
4040
Toolkit tk = Toolkit.getDefaultToolkit();
41-
if ("sun.awt.X11.XToolkit".equals(tk.getClass().getName())) {
42-
System.out.println("Do not test for XAWT Toolkit.");
43-
System.out.println("Passing automatically.");
44-
return;
45-
}
4641

4742
// check that if no listeners added, returns a 0-length array,
4843
// not null
49-
AWTEventListener[] array1 = tk.getAWTEventListeners();
50-
if (array1 == null || array1.length != 0) {
51-
System.out.println("[Empty array test failed!!]");
52-
throw new RuntimeException("Test failed -" +
53-
" didn't return 0-sized array");
54-
}
44+
verify(tk, 0);
5545
System.out.println("[Empty array test passed]");
5646

47+
// check that if a null listener is added, returns an empty array
48+
tk.addAWTEventListener(null, AWTEvent.ACTION_EVENT_MASK);
49+
verify(tk, 0);
50+
NullProxyListener nl = new NullProxyListener();
51+
tk.addAWTEventListener(nl, AWTEvent.ACTION_EVENT_MASK);
52+
verify(tk, 0);
53+
// check that if a null listener is removed, returns an empty array
54+
tk.removeAWTEventListener(null);
55+
verify(tk, 0);
56+
tk.removeAWTEventListener(nl);
57+
verify(tk, 0);
58+
5759
// simple add/get test
5860
DumbListener dl1 = new DumbListener();
5961
final long dl1MASK = AWTEvent.ACTION_EVENT_MASK;
6062
tk.addAWTEventListener(dl1, dl1MASK);
63+
verify(tk, 1);
6164

62-
array1 = tk.getAWTEventListeners();
63-
if (array1 == null || array1.length != 1) {
64-
System.out.println("[Simple add/get test failed!!]");
65-
throw new RuntimeException("Test failed - didn't " +
66-
"return array of 1");
67-
}
65+
AWTEventListener[] array1 = tk.getAWTEventListeners();
6866
AWTEventListenerProxy dp1 = (AWTEventListenerProxy) array1[0];
6967
EventListener getdl1 = dp1.getListener();
7068
if (getdl1 != dl1) {
@@ -165,8 +163,23 @@ public static void main(String[] args) throws Exception {
165163
});
166164
}
167165

166+
private static void verify(Toolkit tk, int expected) {
167+
AWTEventListener[] array = tk.getAWTEventListeners();
168+
if (array == null || array.length != expected) {
169+
System.out.println("[Simple test failed!!]");
170+
throw new RuntimeException(
171+
"Test didn't return " + expected + "-sized array");
172+
}
173+
}
174+
168175
public static class DumbListener implements AWTEventListener {
169176
public DumbListener() {}
170177
public void eventDispatched(AWTEvent e) {}
171178
}
179+
180+
public final static class NullProxyListener extends AWTEventListenerProxy {
181+
public NullProxyListener() {
182+
super(0, null);
183+
}
184+
}
172185
}

0 commit comments

Comments
 (0)