1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
23
23
24
24
/*
25
25
@test
26
- @bug 4290704
26
+ @bug 4290704 8357598
27
27
@summary Test use of AWTEventListenerProxyTest class
28
28
*/
29
29
@@ -38,33 +38,31 @@ public class AWTEventListenerProxyTest {
38
38
public static void main (String [] args ) throws Exception {
39
39
EventQueue .invokeAndWait (() -> {
40
40
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
- }
46
41
47
42
// check that if no listeners added, returns a 0-length array,
48
43
// 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 );
55
45
System .out .println ("[Empty array test passed]" );
56
46
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
+
57
59
// simple add/get test
58
60
DumbListener dl1 = new DumbListener ();
59
61
final long dl1MASK = AWTEvent .ACTION_EVENT_MASK ;
60
62
tk .addAWTEventListener (dl1 , dl1MASK );
63
+ verify (tk , 1 );
61
64
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 ();
68
66
AWTEventListenerProxy dp1 = (AWTEventListenerProxy ) array1 [0 ];
69
67
EventListener getdl1 = dp1 .getListener ();
70
68
if (getdl1 != dl1 ) {
@@ -165,8 +163,23 @@ public static void main(String[] args) throws Exception {
165
163
});
166
164
}
167
165
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
+
168
175
public static class DumbListener implements AWTEventListener {
169
176
public DumbListener () {}
170
177
public void eventDispatched (AWTEvent e ) {}
171
178
}
179
+
180
+ public final static class NullProxyListener extends AWTEventListenerProxy {
181
+ public NullProxyListener () {
182
+ super (0 , null );
183
+ }
184
+ }
172
185
}
0 commit comments