-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8357598: Toolkit.removeAWTEventListener should handle null listener in AWTEventListenerProxy #25401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
72d7788
6fe27d5
bb545a5
3656014
afb10b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2000, 2025, 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 | ||
|
|
@@ -23,7 +23,7 @@ | |
|
|
||
| /* | ||
| @test | ||
| @bug 4290704 | ||
| @bug 4290704 8357598 | ||
| @summary Test use of AWTEventListenerProxyTest class | ||
| */ | ||
|
|
||
|
|
@@ -38,33 +38,31 @@ public class AWTEventListenerProxyTest { | |
| public static void main(String[] args) throws Exception { | ||
| EventQueue.invokeAndWait(() -> { | ||
| Toolkit tk = Toolkit.getDefaultToolkit(); | ||
| if ("sun.awt.X11.XToolkit".equals(tk.getClass().getName())) { | ||
| System.out.println("Do not test for XAWT Toolkit."); | ||
| System.out.println("Passing automatically."); | ||
| return; | ||
| } | ||
|
|
||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not know why it was disabled on XToolkit, seems to work fine. |
||
| // check that if no listeners added, returns a 0-length array, | ||
| // not null | ||
| AWTEventListener[] array1 = tk.getAWTEventListeners(); | ||
| if (array1 == null || array1.length != 0) { | ||
| System.out.println("[Empty array test failed!!]"); | ||
| throw new RuntimeException("Test failed -" + | ||
| " didn't return 0-sized array"); | ||
| } | ||
| verify(tk, 0); | ||
| System.out.println("[Empty array test passed]"); | ||
|
|
||
| // check that if a null listener is added, returns an empty array | ||
| tk.addAWTEventListener(null, AWTEvent.ACTION_EVENT_MASK); | ||
| verify(tk, 0); | ||
| NullProxyListener nl = new NullProxyListener(); | ||
| tk.addAWTEventListener(nl, AWTEvent.ACTION_EVENT_MASK); | ||
| verify(tk, 0); | ||
| // check that if a null listener is removed, returns an empty array | ||
| tk.removeAWTEventListener(null); | ||
| verify(tk, 0); | ||
| tk.removeAWTEventListener(nl); | ||
| verify(tk, 0); | ||
|
|
||
| // simple add/get test | ||
| DumbListener dl1 = new DumbListener(); | ||
| final long dl1MASK = AWTEvent.ACTION_EVENT_MASK; | ||
| tk.addAWTEventListener(dl1, dl1MASK); | ||
| verify(tk, 1); | ||
|
|
||
| array1 = tk.getAWTEventListeners(); | ||
| if (array1 == null || array1.length != 1) { | ||
| System.out.println("[Simple add/get test failed!!]"); | ||
| throw new RuntimeException("Test failed - didn't " + | ||
| "return array of 1"); | ||
| } | ||
| AWTEventListener[] array1 = tk.getAWTEventListeners(); | ||
| AWTEventListenerProxy dp1 = (AWTEventListenerProxy) array1[0]; | ||
| EventListener getdl1 = dp1.getListener(); | ||
| if (getdl1 != dl1) { | ||
|
|
@@ -165,8 +163,23 @@ public static void main(String[] args) throws Exception { | |
| }); | ||
| } | ||
|
|
||
| private static void verify(Toolkit tk, int expected) { | ||
| AWTEventListener[] array = tk.getAWTEventListeners(); | ||
| if (array == null || array.length != expected) { | ||
| System.out.println("[Simple test failed!!]"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this print statement is required?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not, but it follows the common pattern in the test. |
||
| throw new RuntimeException( | ||
| "Test didn't return " + expected + "-sized array"); | ||
| } | ||
| } | ||
|
|
||
| public static class DumbListener implements AWTEventListener { | ||
| public DumbListener() {} | ||
| public void eventDispatched(AWTEvent e) {} | ||
| } | ||
|
|
||
| public final static class NullProxyListener extends AWTEventListenerProxy { | ||
| public NullProxyListener() { | ||
| super(0, null); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the test follow this pattern for jtreg tags. It would be good if you use it too for code consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required, but can be updated…