8139050: -[AWTView draggingEnded:]: unrecognized selector message during drag and drop
authorserb
Fri, 28 Jul 2017 14:39:48 -0700
changeset 47166 dd1972cc4cd4
parent 47165 eb0b0e665926
child 47167 6141bf8d9d85
8139050: -[AWTView draggingEnded:]: unrecognized selector message during drag and drop Reviewed-by: azvegint
jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m
jdk/test/java/awt/dnd/MissingEventsOnModalDialog/MissingEventsOnModalDialogTest.java
jdk/test/javax/swing/dnd/8139050/NativeErrorsInTableDnD.java
--- a/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m	Fri Jul 28 10:26:22 2017 +0530
+++ b/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m	Fri Jul 28 14:39:48 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -770,11 +770,9 @@
     CDragSource *dragSource = self._dragSource;
     NSDragOperation dragOp = NSDragOperationNone;
     
-    if (dragSource != nil)
+    if (dragSource != nil) {
         dragOp = [dragSource draggingSourceOperationMaskForLocal:flag];
-    else if ([super respondsToSelector:@selector(draggingSourceOperationMaskForLocal:)])
-        dragOp = [super draggingSourceOperationMaskForLocal:flag];
-    
+    }
     return dragOp;
 }
 
@@ -784,11 +782,9 @@
     CDragSource *dragSource = self._dragSource;
     NSArray* array = nil;
     
-    if (dragSource != nil)
+    if (dragSource != nil) {
         array = [dragSource namesOfPromisedFilesDroppedAtDestination:dropDestination];
-    else if ([super respondsToSelector:@selector(namesOfPromisedFilesDroppedAtDestination:)])
-        array = [super namesOfPromisedFilesDroppedAtDestination:dropDestination];
-    
+    }
     return array;
 }
 
@@ -797,10 +793,9 @@
     // If draggingSource is nil route the message to the superclass (if responding to the selector):
     CDragSource *dragSource = self._dragSource;
     
-    if (dragSource != nil)
+    if (dragSource != nil) {
         [dragSource draggedImage:image beganAt:screenPoint];
-    else if ([super respondsToSelector:@selector(draggedImage::)])
-        [super draggedImage:image beganAt:screenPoint];
+    }
 }
 
 - (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint operation:(NSDragOperation)operation
@@ -808,10 +803,9 @@
     // If draggingSource is nil route the message to the superclass (if responding to the selector):
     CDragSource *dragSource = self._dragSource;
     
-    if (dragSource != nil)
+    if (dragSource != nil) {
         [dragSource draggedImage:image endedAt:screenPoint operation:operation];
-    else if ([super respondsToSelector:@selector(draggedImage:::)])
-        [super draggedImage:image endedAt:screenPoint operation:operation];
+    }
 }
 
 - (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint
@@ -819,10 +813,9 @@
     // If draggingSource is nil route the message to the superclass (if responding to the selector):
     CDragSource *dragSource = self._dragSource;
     
-    if (dragSource != nil)
+    if (dragSource != nil) {
         [dragSource draggedImage:image movedTo:screenPoint];
-    else if ([super respondsToSelector:@selector(draggedImage::)])
-        [super draggedImage:image movedTo:screenPoint];
+    }
 }
 
 - (BOOL)ignoreModifierKeysWhileDragging
@@ -831,11 +824,9 @@
     CDragSource *dragSource = self._dragSource;
     BOOL result = FALSE;
     
-    if (dragSource != nil)
+    if (dragSource != nil) {
         result = [dragSource ignoreModifierKeysWhileDragging];
-    else if ([super respondsToSelector:@selector(ignoreModifierKeysWhileDragging)])
-        result = [super ignoreModifierKeysWhileDragging];
-    
+    }
     return result;
 }
 
@@ -849,11 +840,9 @@
     CDropTarget *dropTarget = self._dropTarget;
     NSDragOperation dragOp = NSDragOperationNone;
     
-    if (dropTarget != nil)
+    if (dropTarget != nil) {
         dragOp = [dropTarget draggingEntered:sender];
-    else if ([super respondsToSelector:@selector(draggingEntered:)])
-        dragOp = [super draggingEntered:sender];
-    
+    }
     return dragOp;
 }
 
@@ -863,11 +852,9 @@
     CDropTarget *dropTarget = self._dropTarget;
     NSDragOperation dragOp = NSDragOperationNone;
     
-    if (dropTarget != nil)
+    if (dropTarget != nil) {
         dragOp = [dropTarget draggingUpdated:sender];
-    else if ([super respondsToSelector:@selector(draggingUpdated:)])
-        dragOp = [super draggingUpdated:sender];
-    
+    }
     return dragOp;
 }
 
@@ -876,10 +863,9 @@
     // If draggingDestination is nil route the message to the superclass:
     CDropTarget *dropTarget = self._dropTarget;
     
-    if (dropTarget != nil)
+    if (dropTarget != nil) {
         [dropTarget draggingExited:sender];
-    else if ([super respondsToSelector:@selector(draggingExited:)])
-        [super draggingExited:sender];
+    }
 }
 
 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
@@ -888,11 +874,9 @@
     CDropTarget *dropTarget = self._dropTarget;
     BOOL result = FALSE;
     
-    if (dropTarget != nil)
+    if (dropTarget != nil) {
         result = [dropTarget prepareForDragOperation:sender];
-    else if ([super respondsToSelector:@selector(prepareForDragOperation:)])
-        result = [super prepareForDragOperation:sender];
-    
+    }
     return result;
 }
 
@@ -902,11 +886,9 @@
     CDropTarget *dropTarget = self._dropTarget;
     BOOL result = FALSE;
     
-    if (dropTarget != nil)
+    if (dropTarget != nil) {
         result = [dropTarget performDragOperation:sender];
-    else if ([super respondsToSelector:@selector(performDragOperation:)])
-        result = [super performDragOperation:sender];
-    
+    }
     return result;
 }
 
@@ -915,10 +897,9 @@
     // If draggingDestination is nil route the message to the superclass:
     CDropTarget *dropTarget = self._dropTarget;
     
-    if (dropTarget != nil)
+    if (dropTarget != nil) {
         [dropTarget concludeDragOperation:sender];
-    else if ([super respondsToSelector:@selector(concludeDragOperation:)])
-        [super concludeDragOperation:sender];
+    }
 }
 
 - (void)draggingEnded:(id <NSDraggingInfo>)sender
@@ -926,10 +907,9 @@
     // If draggingDestination is nil route the message to the superclass:
     CDropTarget *dropTarget = self._dropTarget;
     
-    if (dropTarget != nil)
+    if (dropTarget != nil) {
         [dropTarget draggingEnded:sender];
-    else if ([super respondsToSelector:@selector(draggingEnded:)])
-        [super draggingEnded:sender];
+    }
 }
 
 /********************************  END NSDraggingDestination Interface  ********************************/
--- a/jdk/test/java/awt/dnd/MissingEventsOnModalDialog/MissingEventsOnModalDialogTest.java	Fri Jul 28 10:26:22 2017 +0530
+++ b/jdk/test/java/awt/dnd/MissingEventsOnModalDialog/MissingEventsOnModalDialogTest.java	Fri Jul 28 14:39:48 2017 -0700
@@ -41,20 +41,44 @@
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.concurrent.TimeUnit;
+
 /*
  * @test
  * @key headful
- * @bug 8134917
+ * @bug 8134917 8139050
  * @summary [macosx] JOptionPane doesn't receive mouse events when opened from a drop event
- * @author Alexandr Scherbatiy
+ * @run main MissingEventsOnModalDialogTest RUN_PROCESS
  */
 public class MissingEventsOnModalDialogTest {
 
+    private static final String RUN_PROCESS = "RUN_PROCESS";
+    private static final String RUN_TEST = "RUN_TEST";
+    private static boolean exception = false;
     private static volatile boolean passed = false;
 
     public static void main(String[] args) throws Exception {
-        Frame sourceFrame = createFrame("Source Frame", 0, 0);
-        Frame targetFrame = createFrame("Target Frame", 250, 250);
+        String command = args.length < 1 ? RUN_TEST : args[0];
+        switch (command) {
+            case RUN_PROCESS:
+                runProcess();
+                break;
+            case RUN_TEST:
+                runTest();
+                break;
+            default:
+                throw new RuntimeException("Unknown command: " + command);
+        }
+    }
+
+    private static void runTest() throws Exception {
+        Frame sourceFrame = createFrame("Source Frame", 100, 100);
+        Frame targetFrame = createFrame("Target Frame", 350, 350);
 
         DragSource defaultDragSource
                 = DragSource.getDefaultDragSource();
@@ -237,4 +261,50 @@
             throw new RuntimeException(e);
         }
     }
+
+    private static void runProcess() throws Exception {
+        String javaPath = System.getProperty("java.home", "");
+        String command = javaPath + File.separator + "bin" + File.separator + "java"
+                + " " + MissingEventsOnModalDialogTest.class.getName() + " " + RUN_TEST;
+
+        Process process = Runtime.getRuntime().exec(command);
+        boolean processExit = process.waitFor(20, TimeUnit.SECONDS);
+
+        StringBuilder inStream = new StringBuilder();
+        StringBuilder errStream = new StringBuilder();
+        checkErrors(process.getErrorStream(), errStream);
+        checkErrors(process.getInputStream(), inStream);
+
+        if (exception) {
+            System.out.println(inStream);
+            System.err.println(errStream);
+            throw new RuntimeException("Exception in the output!");
+        }
+
+        if (!processExit) {
+            process.destroy();
+            throw new RuntimeException(""
+                    + "The sub process has not exited!");
+        }
+    }
+
+    private static boolean containsError(String line) {
+        line = line.toLowerCase();
+        return line.contains("exception") || line.contains("error")
+                || line.contains("selector");
+    }
+
+    private static void checkErrors(InputStream in, StringBuilder stream) throws IOException {
+        try (BufferedReader bufferedReader
+                = new BufferedReader(new InputStreamReader(in))) {
+
+            String line = null;
+            while ((line = bufferedReader.readLine()) != null) {
+                if (!exception) {
+                    exception = containsError(line);
+                }
+                stream.append(line).append("\n");
+            }
+        }
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/dnd/8139050/NativeErrorsInTableDnD.java	Fri Jul 28 14:39:48 2017 -0700
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2017, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Rectangle;
+import java.awt.event.InputEvent;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.JFrame;
+import javax.swing.JTable;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+
+import static javax.swing.UIManager.getInstalledLookAndFeels;
+
+/**
+ * @test
+ * @bug 8139050
+ * @library ../../../../lib/testlibrary
+ * @build ExtendedRobot
+ * @run main/othervm/timeout=360 -Xcheck:jni NativeErrorsInTableDnD
+ */
+public final class NativeErrorsInTableDnD {
+
+    private static JFrame frame;
+
+    private static volatile Rectangle bounds;
+
+    public static void main(final String[] args) throws Exception {
+        if (args.length == 0) {
+            createChildProcess();
+            return;
+        }
+        for (final UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {
+            SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
+
+            SwingUtilities.invokeAndWait(() -> {
+                final JTable table = new JTable(10, 10);
+                frame = new JFrame();
+                frame.setUndecorated(true);
+                table.setDragEnabled(true);
+                table.selectAll();
+                frame.add(table);
+                frame.pack();
+                frame.setLocationRelativeTo(null);
+                frame.setVisible(true);
+            });
+            final ExtendedRobot r = new ExtendedRobot();
+            r.waitForIdle();
+            SwingUtilities.invokeAndWait(() -> {
+                bounds = frame.getBounds();
+            });
+            for (int i = 0; i < 5; ++i) {
+                int x1 = bounds.x + bounds.width / 4;
+                int y1 = bounds.y + bounds.height / 4;
+                r.setAutoDelay(50);
+                // Special sequence of clicks which reproduce the problem
+                r.mouseMove(bounds.x + bounds.width / 7, y1);
+                r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+                r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+                r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+                r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+                r.mouseMove(x1, y1);
+                r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+                r.setAutoDelay(0);
+                r.glide(x1, y1, x1 + bounds.width / 4, y1 + bounds.height / 4);
+                r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            }
+            SwingUtilities.invokeAndWait(() -> {
+                frame.dispose();
+            });
+            r.waitForIdle();
+        }
+    }
+
+    static void createChildProcess() throws Exception {
+        final String javaPath = System.getProperty("java.home");
+        final String classPathDir = System.getProperty("java.class.path");
+        doExec(javaPath + File.separator + "bin" + File.separator + "java",
+               "-cp", classPathDir, "NativeErrorsInTableDnD", "start");
+    }
+
+    static void doExec(final String... cmds) throws Exception {
+        Process p;
+        final ProcessBuilder pb = new ProcessBuilder(cmds);
+        for (final String cmd : cmds) {
+            System.out.print(cmd + " ");
+        }
+        System.out.println();
+        BufferedReader rdr;
+        final List<String> errorList = new ArrayList<>();
+        final List<String> outputList = new ArrayList<>();
+        p = pb.start();
+        rdr = new BufferedReader(new InputStreamReader(p.getInputStream()));
+        String in = rdr.readLine();
+        while (in != null) {
+            outputList.add(in);
+            in = rdr.readLine();
+            System.out.println(in);
+        }
+        rdr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
+        in = rdr.readLine();
+        while (in != null) {
+            errorList.add(in);
+            in = rdr.readLine();
+            System.err.println(in);
+        }
+        p.waitFor();
+        p.destroy();
+
+        if (!errorList.isEmpty()) {
+            throw new RuntimeException("Error log is not empty");
+        }
+        final int exit = p.exitValue();
+        if (exit != 0) {
+            throw new RuntimeException("Exit status = " + exit);
+        }
+    }
+
+    private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) {
+        try {
+            UIManager.setLookAndFeel(laf.getClassName());
+            System.out.println("LookAndFeel: " + laf.getClassName());
+        } catch (ClassNotFoundException | InstantiationException |
+                UnsupportedLookAndFeelException | IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}