1 /* 2 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 @test 26 @bug 4913324 27 @author Oleg Sukhodolsky: area=eventqueue 28 @run main/timeout=30 PushPopTest 29 */ 30 31 import java.awt.*; 32 import java.awt.event.*; 33 import java.util.EmptyStackException; 34 import sun.awt.SunToolkit; 35 36 public class PushPopTest { 37 38 public static Frame frame; 39 public static void main(String[] args) { 40 frame = new Frame(""); 41 frame.pack(); 42 43 Runnable dummy = new Runnable() { 44 public void run() { 45 System.err.println("Dummy is here."); 46 System.err.flush(); 47 } 48 }; 49 EventQueue seq = Toolkit.getDefaultToolkit().getSystemEventQueue(); 50 MyEventQueue1 eq1 = new MyEventQueue1(); 51 MyEventQueue2 eq2 = new MyEventQueue2(); 52 EventQueue.invokeLater(dummy); 53 54 seq.push(eq1); 55 EventQueue.invokeLater(dummy); 56 57 eq1.push(eq2); 58 EventQueue.invokeLater(dummy); 59 Runnable runnable = new Runnable() { 60 public void run() { 61 System.err.println("Dummy from SunToolkit"); 62 System.err.flush(); 63 } 64 }; 65 InvocationEvent ie = new InvocationEvent(eq2, runnable, null, false); 66 // System.err.println(ie); 67 SunToolkit.postEvent(SunToolkit.targetToAppContext(frame), ie); 68 eq1.pop(); 69 frame.dispose(); 70 } 71 } 72 73 class MyEventQueue1 extends EventQueue { 74 75 public void pop() { 76 super.pop(); 77 } 78 } 79 80 class MyEventQueue2 extends EventQueue { 81 82 protected void pop() { 83 System.err.println("pop2()"); 84 Thread.dumpStack(); 85 try { 86 EventQueue.invokeAndWait(new Runnable() { 87 public void run() { 88 Runnable runnable = new Runnable() { 89 public void run() { 90 System.err.println("Dummy from pop"); 91 System.err.flush(); 92 } 93 }; 94 InvocationEvent ie = new InvocationEvent(MyEventQueue2.this, runnable, null, false); 95 SunToolkit.postEvent(SunToolkit.targetToAppContext(PushPopTest.frame), ie); 96 postEvent(ie); 97 } 98 }); 99 } catch (InterruptedException ie) { 100 ie.printStackTrace(); 101 } catch (java.lang.reflect.InvocationTargetException ie) { 102 ie.printStackTrace(); 103 } 104 super.pop(); 105 } 106 }