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