Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8024061

Exception thrown when drag and drop between two components is executed quickly

    Details

    • Subcomponent:
    • Resolved In Build:
      b15
    • CPU:
      generic
    • OS:
      linux

      Backports

        Description

        Dragging and dropping an object from one panel to another very quickly causes an exception. If the DnD operation is otherwise performed at a normal speed, the exception does not occur. It seems that the problem is a race condition between the XAWT and the EDT threads.

        When the DnD operation is initiated, the SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable() is called to
        set the Transferable involved in the DnD operation; that method stores it into a protected static variable. When the processEnterMessage() is called, the value of the static variable is copied into an instance variable called "local"; this instance variable is then set to null when the paired processExitMessage() is called. The static Transferable variable is finally set to null by the cleanup() method of the SunDragSourceContextPeer class.

        What happens is that if the DnD operation is performed quickly relatively to the processing that the application has to do during the DnD session (grabbing an object from one view, dragging and dropping it on another view in the time frame of a second or less) the cleanup() method gets called before the processEnterMessage() relative to the target view is entered. Consequently, when the processEnterMessage() executes, the static Transferable variable is null and so null becomes also the "local" variable. This makes the getTransferData() chain of calls follow a different path, which ends up with the exception:

        java.lang.ClassCastException: DnD$DropObject cannot be cast to java.io.InputStream
                at sun.awt.datatransfer.DataTransferer.translateTransferable(DataTransferer.java:1186)
                at sun.awt.datatransfer.DataTransferer$6.run(DataTransferer.java:2145)
                at sun.awt.datatransfer.DataTransferer.processDataConversionRequests(DataTransferer.java:2202)
                at sun.awt.X11.XSelection.waitForSelectionNotify(XSelection.java:200)
                at sun.awt.X11.XSelection.getData(XSelection.java:340)
                at sun.awt.X11.XDnDDropTargetProtocol.getData(XDnDDropTargetProtocol.java:841)
                at sun.awt.X11.XDropTargetContextPeer.getNativeData(XDropTargetContextPeer.java:132)
                at sun.awt.dnd.SunDropTargetContextPeer.getTransferData(SunDropTargetContextPeer.java:245)
                at sun.awt.datatransfer.TransferableProxy.getTransferData(TransferableProxy.java:56)
                at java.awt.dnd.DropTargetContext$TransferableProxy.getTransferData(DropTargetContext.java:359)
                at DnD$DnDPanel$3.dragEnter(DnD.java:232)
                at java.awt.dnd.DropTarget.dragEnter(DropTarget.java:341)
                at sun.awt.dnd.SunDropTargetContextPeer.processEnterMessage(SunDropTargetContextPeer.java:312)
                at sun.awt.X11.XDropTargetContextPeer.processEnterMessage(XDropTargetContextPeer.java:146)
                at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEnterEvent(SunDropTargetContextPeer.java:779)
                at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(SunDropTargetContextPeer.java:747)
                at sun.awt.dnd.SunDropTargetEvent.dispatch(SunDropTargetEvent.java:30)
                at java.awt.Component.dispatchEventImpl(Component.java:4508)
                at java.awt.Container.dispatchEventImpl(Container.java:2099)
                at java.awt.Component.dispatchEvent(Component.java:4481)
                at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
                at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:4366)
                at java.awt.LightweightDispatcher.processDropTargetEvent(Container.java:4304)
                at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4163)
                at java.awt.Container.dispatchEventImpl(Container.java:2085)
                at java.awt.Window.dispatchEventImpl(Window.java:2478)
                at java.awt.Component.dispatchEvent(Component.java:4481)
                at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
                at java.awt.EventQueue.access$000(EventQueue.java:84)
                at java.awt.EventQueue$1.run(EventQueue.java:602)
                at java.awt.EventQueue$1.run(EventQueue.java:600)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
                at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
                at java.awt.EventQueue$2.run(EventQueue.java:616)
                at java.awt.EventQueue$2.run(EventQueue.java:614)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
                at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
                at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
                at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
                at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
                at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
                at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
                at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

        java.io.IOException: Owner failed to convert data
                at sun.awt.X11.XSelection.validateDataGetter(XSelection.java:486)
                at sun.awt.X11.XSelection.getData(XSelection.java:350)
                at sun.awt.X11.XDnDDropTargetProtocol.getData(XDnDDropTargetProtocol.java:841)
                at sun.awt.X11.XDropTargetContextPeer.getNativeData(XDropTargetContextPeer.java:132)
                at sun.awt.dnd.SunDropTargetContextPeer.getTransferData(SunDropTargetContextPeer.java:245)
                at sun.awt.datatransfer.TransferableProxy.getTransferData(TransferableProxy.java:56)
                at java.awt.dnd.DropTargetContext$TransferableProxy.getTransferData(DropTargetContext.java:359)
                at DnD$DnDPanel$3.dragEnter(DnD.java:232)
                at java.awt.dnd.DropTarget.dragEnter(DropTarget.java:341)
                at sun.awt.dnd.SunDropTargetContextPeer.processEnterMessage(SunDropTargetContextPeer.java:312)
                at sun.awt.X11.XDropTargetContextPeer.processEnterMessage(XDropTargetContextPeer.java:146)
                at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEnterEvent(SunDropTargetContextPeer.java:779)
                at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(SunDropTargetContextPeer.java:747)
                at sun.awt.dnd.SunDropTargetEvent.dispatch(SunDropTargetEvent.java:30)
                at java.awt.Component.dispatchEventImpl(Component.java:4508)
                at java.awt.Container.dispatchEventImpl(Container.java:2099)
                at java.awt.Component.dispatchEvent(Component.java:4481)
                at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
                at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:4366)
                at java.awt.LightweightDispatcher.processDropTargetEvent(Container.java:4304)
                at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4163)
                at java.awt.Container.dispatchEventImpl(Container.java:2085)
                at java.awt.Window.dispatchEventImpl(Window.java:2478)
                at java.awt.Component.dispatchEvent(Component.java:4481)
                at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
                at java.awt.EventQueue.access$000(EventQueue.java:84)
                at java.awt.EventQueue$1.run(EventQueue.java:602)
                at java.awt.EventQueue$1.run(EventQueue.java:600)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
                at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
                at java.awt.EventQueue$2.run(EventQueue.java:616)
                at java.awt.EventQueue$2.run(EventQueue.java:614)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
                at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
                at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
                at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
                at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
                at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
                at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
                at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


        This issue occurs when the processing of the various listeners' calls involved is not trivial. I found that the most affecting one is the
        dragGestureRecognized() of the DragGestureListener. I have then created a test case that introduces a delay in that method. The test java class, called DnD is attached to this report.

        To run without delay execute:
        java DnD

        To run with dealy execute:
        java DnD <millis>
        where <millis> is an integer number specifying the delay affecting dragGestureRecognized(). A value of 200 should make the exception occurr.

        When the app is running try to drag and drop the blue square from the yellow panel to the pink one very quickly.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  aivanov Alexey Ivanov
                  Reporter:
                  anashaty Anton Nashatyrev (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: