JDK-4760364 : X11: Deadlock when two apps request selection data from each other
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-10-09
  • Updated: 2002-11-01
  • Resolved: 2002-11-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
Related Reports
Relates :  
Description

Name: dsR10078			Date: 10/09/2002

###@###.###
The bug can be reproduced on Solaris/Linux with the following test case:
----------------------------------------------------------------------------
import java.awt.*;
import java.awt.datatransfer.*;

public class Test {
    public static void main(String[] args) {
        Toolkit tk = Toolkit.getDefaultToolkit();
        Clipboard c1 = null;
        Clipboard c2 = null;
        if (args.length == 0) {
            c1 = tk.getSystemClipboard();
            c2 = tk.getSystemSelection();
        } else {
            c1 = tk.getSystemSelection();
            c2 = tk.getSystemClipboard();
        }
        final Clipboard clipboard = c2;
        final Transferable t = new StringSelection("TEXT");
        c1.setContents(t, null);
        for (int i = 0; i < 100; i++) {
            try {
                EventQueue.invokeAndWait(new Runnable() {
                        public void run() {
                            Transferable t = clipboard.getContents(null);
                            try {
                                System.err.println("data=" +
                                                   t.getTransferData(DataFlavor.stringFlavor));
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.err.println("i=" + i);
        }                                   
    }
}
----------------------------------------------------------------------------
Steps to reproduce:
1.Compile the test case.
2.Run simultaneosly two instances of this test - one with an arbitrary command-line 
  argument and the other without any arguments. For example:
   # java Test 1
   # java Test
3.Note that they start printing to the console and then both get blocked.
The thread dump at the point of deadlock is as follows:
----------------------------------------------------------------------------
Full thread dump Java HotSpot(TM) Client VM (1.4.2-beta-b02 mixed mode):

"AWT-EventQueue-0" prio=1 tid=0x081cee30 nid=0x7b14 in Object.wait() [41617000..416178cc]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x4828ee40> (a java.lang.Class)
        at sun.awt.datatransfer.ClipboardTransferable.getClipboardData(Native Method)
        at sun.awt.datatransfer.ClipboardTransferable.fetchOneFlavor(ClipboardTransferable.java:106)
        at sun.awt.datatransfer.ClipboardTransferable.<init>(ClipboardTransferable.java:80)
        at sun.awt.datatransfer.SunClipboard.getContents(SunClipboard.java:96)
        - locked <0x441d0308> (a sun.awt.motif.X11Clipboard)
        at Test$1.run(Test.java:23)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:171)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:449)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

"AWT-Motif" daemon prio=1 tid=0x081be6a0 nid=0x7b12 in Object.wait() [41595000..415968cc]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x4828ee40> (a java.lang.Class)
        at sun.awt.motif.MToolkitThreadBlockedHandler.enter(Native Method)
        at sun.awt.datatransfer.DataTransferer.convertData(DataTransferer.java:2026)
        at sun.awt.motif.MToolkit.run(Native Method)
        at java.lang.Thread.run(Thread.java:536)

"AWT-Shutdown" prio=1 tid=0x081be328 nid=0x7b10 in Object.wait() [41515000..415158cc]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x4464c288> (a java.lang.Object)
        at java.lang.Object.wait(Object.java:426)
        at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:259)
        - locked <0x4464c288> (a java.lang.Object)
        at java.lang.Thread.run(Thread.java:536)

"Signal Dispatcher" daemon prio=1 tid=0x08093648 nid=0x7b0b waiting on condition [0..0]

"Finalizer" daemon prio=1 tid=0x0808e588 nid=0x7b01 in Object.wait() [40bdb000..40bdb8cc]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x44645448> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
        - locked <0x44645448> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)

"Reference Handler" daemon prio=1 tid=0x0808cad8 nid=0x7b00 in Object.wait() [40b5a000..40b5a8cc]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x446454b0> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:426)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:113)
        - locked <0x446454b0> (a java.lang.ref.Reference$Lock)

"main" prio=1 tid=0x08051ef8 nid=0x7afd in Object.wait() [bfffc000..bfffce88]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x44145f60> (a java.awt.EventQueue$1$AWTInvocationLock)
        at java.lang.Object.wait(Object.java:426)
        at java.awt.EventQueue.invokeAndWait(EventQueue.java:824)
        - locked <0x44145f60> (a java.awt.EventQueue$1$AWTInvocationLock)
        at Test.main(Test.java:21)

"VM Thread" prio=1 tid=0x080898f8 nid=0x7aff runnable 

"VM Periodic Task Thread" prio=1 tid=0x08092168 nid=0x7b07 waiting on condition 
"Suspend Checker Thread" prio=1 tid=0x08092bd8 nid=0x7b09 runnable 
----------------------------------------------------------------------------
This behavior was introduced with the fix for 4558797. 
Before that fix the deadlock is not reproducible, but the two apps continuously throw 
IOExceptions reporting data conversion failure:
----------------------------------------------------------------------------
java.io.IOException: Failed to get selection targets
        at sun.awt.datatransfer.ClipboardTransferable.getClipboardData(Native Method)
        at sun.awt.datatransfer.ClipboardTransferable.fetchOneFlavor(ClipboardTransferable.java:106)
        at sun.awt.datatransfer.ClipboardTransferable.<init>(ClipboardTransferable.java:80)
        at sun.awt.datatransfer.SunClipboard.getContents(SunClipboard.java:96)
        at Test$1.run(Test.java:23)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:171)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:449)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
----------------------------------------------------------------------------

###@###.### 2002-10-09
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis mantis-b06
14-06-2004

WORK AROUND Name: dsR10078 Date: 10/09/2002 ======================================================================
11-06-2004

SUGGESTED FIX Name: dsR10078 Date: 10/10/2002 Keep track of the data conversion requests posted from the toolkit thread to the event dispatch thread. While waiting for SelectionNotify on the event dispatch thread, periodically check if there is a pending request for the data conversion on the event queue and process it immediatelly, unblocking the toolkit thread. ###@###.### 2002-10-10 ======================================================================
10-10-2002

EVALUATION Name: dsR10078 Date: 10/10/2002 The evaluation for 4558797 states that the deadlock between the event dispatch thread and the toolkit thread documented in 4558745 is not possible anymore. However, there is another deadlock condition that still can occur: There are two Java applications running in parallel. One of them acquires ownership of the primary selection and the other - of the clipboard selection. For each of the two apps at the same time: - the contents of the selection owned by the other app is requested on the event dispatch thread; - SelectionRequest event is posted to the other app and the event dispatch thread waits until the toolkit thread processes SelectionNotify from the other app; - the toolkit thread receives SelectionRequests event from the other app, posts a Runnable to the event dispatch thread to get the requested data and waits until it is executed. At this point both apps are blocked waiting for each other. ###@###.### 2002-10-10 ======================================================================
10-10-2002