6738181: api/java_awt/Toolkit/index.html#GetAWTEventListeners Fails with:empty array returned unexpectedly
Summary: redirect getAWTEventListeners(long l) from Headless to underlying toolkit.
Reviewed-by: art
--- a/jdk/src/share/classes/sun/awt/HeadlessToolkit.java Tue Aug 12 12:00:46 2008 +0400
+++ b/jdk/src/share/classes/sun/awt/HeadlessToolkit.java Thu Sep 04 17:20:25 2008 +0400
@@ -456,6 +456,10 @@
return tk.getAWTEventListeners();
}
+ public AWTEventListener[] getAWTEventListeners(long eventMask) {
+ return tk.getAWTEventListeners(eventMask);
+ }
+
public boolean isDesktopSupported() {
return false;
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Toolkit/Headless/AWTEventListener/AWTListener.java Thu Sep 04 17:20:25 2008 +0400
@@ -0,0 +1,48 @@
+/*
+ @test
+ @bug 6738181
+ @library ../../../regtesthelpers
+ @build Sysout
+ @summary Toolkit.getAWTEventListeners returns empty array
+ @author andrei dmitriev: area=awt.headless
+ @run main/othervm -Djava.awt.headless=true AWTListener
+*/
+
+/**
+ * In a headless mode add a listener for container events.
+ * Check if a single listener is still assigned to the Toolkit class.
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import test.java.awt.regtesthelpers.Sysout;
+
+public class AWTListener {
+ public static void main(String []s) {
+ Toolkit toolkit = Toolkit.getDefaultToolkit();
+
+ AWTEventListener orig = new AWTEventListener() {
+ public void eventDispatched(AWTEvent event) { }
+ };
+
+ Sysout.println("Test: listener to add = " +orig);
+ toolkit.addAWTEventListener(orig, AWTEvent.CONTAINER_EVENT_MASK);
+
+ for (AWTEventListener l: toolkit.getAWTEventListeners()){
+ Sysout.println("Test: listener = " +l+" ");
+ }
+
+ if ( toolkit.getAWTEventListeners().length == 0 ) {
+ throw new RuntimeException("Case 1. An empty array returned unexpectedly");
+ }
+
+ for (AWTEventListener l: toolkit.getAWTEventListeners(AWTEvent.CONTAINER_EVENT_MASK)){
+ Sysout.println("Test: listener = " +l);
+ }
+
+ if ( toolkit.getAWTEventListeners(AWTEvent.CONTAINER_EVENT_MASK).length == 0 ) {
+ throw new RuntimeException("Case 2. An empty array returned unexpectedly");
+ }
+ Sysout.println("Test PASSED");
+ }
+}