1 /* 2 * Copyright (c) 2013, 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 @summary JVM crash if the frame is disposed in DropTargetListener 26 * @key headful 27 * @author Petr Pchelko 28 * @library ../../regtesthelpers 29 * @build Util 30 * @compile DisposeFrameOnDragTest.java 31 * @run main/othervm DisposeFrameOnDragTest 32 */ 33 import java.awt.AWTException; 34 import java.awt.Point; 35 import java.awt.Robot; 36 import java.awt.dnd.DropTargetAdapter; 37 import java.awt.dnd.DropTargetDragEvent; 38 import java.awt.dnd.DropTargetDropEvent; 39 import java.awt.event.InputEvent; 40 import java.lang.reflect.InvocationTargetException; 41 import java.util.TooManyListenersException; 42 import javax.swing.JFrame; 43 import javax.swing.JTextArea; 44 import javax.swing.SwingUtilities; 45 import test.java.awt.regtesthelpers.Util; 46 47 public class DisposeFrameOnDragTest { 48 49 private static JTextArea textArea; 50 51 public static void main(String[] args) throws Throwable { 52 53 SwingUtilities.invokeAndWait(new Runnable() { 54 @Override 55 public void run() { 56 constructTestUI(); 57 } 58 }); 59 60 Util.waitForIdle(null); 61 try { 62 Point loc = textArea.getLocationOnScreen(); 63 Util.drag(new Robot(), 64 new Point((int) loc.x + 3, (int) loc.y + 3), 65 new Point((int) loc.x + 40, (int) loc.y + 40), 66 InputEvent.BUTTON1_MASK); 67 } catch (AWTException ex) { 68 throw new RuntimeException("Could not initiate a drag operation"); 69 } 70 Util.waitForIdle(null); 71 } 72 73 private static void constructTestUI() { 74 final JFrame frame = new JFrame("Test frame"); 75 textArea = new JTextArea("Drag Me!"); 76 try { 77 textArea.getDropTarget().addDropTargetListener(new DropTargetAdapter() { 78 @Override 79 public void drop(DropTargetDropEvent dtde) { 80 //IGNORE 81 } 82 83 @Override 84 public void dragOver(DropTargetDragEvent dtde) { 85 frame.dispose(); 86 } 87 }); 88 } catch (TooManyListenersException ex) { 89 throw new RuntimeException(ex); 90 } 91 textArea.setSize(100, 100); 92 textArea.setDragEnabled(true); 93 textArea.select(0, textArea.getText().length()); 94 frame.add(textArea); 95 frame.setBounds(100, 100, 100, 100); 96 frame.setVisible(true); 97 } 98 }