JDK-6182905 : stack trace when using getSystemClipboard().addFlavorListener() and DnD
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P1
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2004-10-21
  • Updated: 2007-04-21
  • Resolved: 2007-04-21
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Linux btu5h 2.4.20-31.9 #1 Tue Apr 13 17:38:16 EDT 2004 i686 athlon i386 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
When I use Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener
I will get a stack trace whenever I do a Drag and Drop operation that involves a move. This is true of *any* component using TransferHandler.

If I do not have Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener in
my program, all works just fine.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample program I give later in this report.
Attempt to drag and drop between the two text fields.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Drag and Drop works fine.

ACTUAL -
Strack trace (although Dnd seems to have worked)


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception on Toolkit thread: java.lang.NullPointerException
java.lang.NullPointerException
        at sun.awt.X11.XSelection.checkChange(XSelection.java:701)
        at sun.awt.X11.XSelection.access$200(XSelection.java:28)
        at sun.awt.X11.XSelection$SelectionEventHandler.dispatchEvent(XSelection.java:710)
        at sun.awt.X11.XToolkit.dispatchEvent(XToolkit.java:408)
        at sun.awt.X11.XToolkit.run(XToolkit.java:493)
        at sun.awt.X11.XToolkit.run(XToolkit.java:438)
        at java.lang.Thread.run(Thread.java:595)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.* ;
import java.awt.* ;
import java.awt.datatransfer.* ;
                                                                                                                        
public class test extends JFrame {
        public test() {
                getContentPane().setLayout(new FlowLayout()) ;
                JTextField jt1 = new JTextField("abc",20) ;
                jt1.setDragEnabled(true) ;
                JTextField jt2 = new JTextField("def",20) ;
                jt2.setDragEnabled(true) ;
                add(jt1) ;
                add(jt2) ;
        }
                                                                                                                        
    public static void main(String args[]) {
        Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(new FlavorListener() {
            public void flavorsChanged(FlavorEvent e) {
            }
        }) ;
        test t = new test() ;
        t.pack() ;
        t.setVisible(true) ;
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Don't use Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener
###@###.### 10/21/04 22:07 GMT

Comments
EVALUATION it looks like this is a duplicate of 6511815 which has been fixed in 7.0 and 6u2 b02.
2007-04-21

EVALUATION Currently we have a P1 bug http://www.netbeans.org/issues/show_bug.cgi?id=100272 that is being blocked by this issue. We need a solution / or workaround for this asap before the Javaone. Thanks.
2007-04-20

SUGGESTED FIX *** /tmp/geta25410Fri Oct 22 13:37:34 2004 --- XSelection.javaFri Oct 22 13:36:44 2004 *************** *** 673,678 **** --- 673,685 ---- return; } + XAtom selectionAtom = XAtom.get(xse.get_selection()); + XSelection selection = getSelection(selectionAtom); + if (selection == null || selection.clipboard == null) { + // there is no such selection or the selection is used by DnD + return; + } + long propertyAtom = xse.get_property(); long[] formats = null; *************** *** 694,705 **** } } ! XAtom selectionAtom = XAtom.get(xse.get_selection()); ! XSelection selection = getSelection(selectionAtom); ! if (selection != null) { ! selection.isSelectionNotifyProcessed = true; ! selection.clipboard.checkChange(formats); ! } } private static class SelectionEventHandler implements XEventDispatcher { --- 701,708 ---- } } ! selection.isSelectionNotifyProcessed = true; ! selection.clipboard.checkChange(formats); } private static class SelectionEventHandler implements XEventDispatcher { ###@###.### 10/22/04 09:52 GMT
2004-10-22

EVALUATION This bug is specific to XAWT (which is default on Linux). The class XSelection represents selections used by DnD as well as the selection corresponding to the system clipboard. Tracking changes of flavors is not applicable to selections used by DnD. Should bar DnD selections from tracking changes of flavors more carefully than it's done now. ###@###.### 10/22/04 09:52 GMT
2004-10-22