JDK-6310757 : NPE drag-n-drop a swing JTree node (from a JPanel) onto an empty JPanel
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0u3
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2005-08-13
  • Updated: 2010-08-19
  • Resolved: 2005-08-15
Related Reports
Duplicate :  
Relates :  
Exception happens in the  restoreComponentState method in "javax/swing/plaf/basic/BasicTreeUI.java"

//Following is a 1.4.2_04 based source snapshot where NPE happens. 
           * called to restore the state of a component  
           * because a drop was not performed. 
          protected void restoreComponentState(JComponent comp) { 
              JTree tree = (JTree)comp; 
              tree.setSelectionRows(selectedIndices);  <-- NPE happens here,since tree is not checked for Null 

Tested env. Java Studio Enterprise Build 050713_14, winxp, jdk1.5.0_03
Steps :
0. Install JSE from above location, then open JSE IDE from 
<install location>/ide/bin/runide.exe
1. Create a platform independent UML project (File-> New Project)
2. create a class diagram in the UML project
3. Bring up design center window using the menu
   "Window->UML Modelling->Design Center"
4. Select any of the  design center nodes and try to drag it into the
   almostempty area above the tree, that just has a funnel and a refresh icons

you will see an exception in the console with following stack trace :

        at javax.swing.plaf.basic.BasicTreeUI$TreeDropTargetListener.restoreComp
        at javax.swing.plaf.basic.BasicDropTargetListener.dragExit(BasicDropTarg
        at javax.swing.TransferHandler$SwingDropTarget.dragExit(TransferHandler.
        at sun.awt.dnd.SunDropTargetContextPeer.processExitMessage(SunDropTarget
        at sun.awt.dnd.SunDropTargetContextPeer.access$700(SunDropTargetContextP
        at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchExitEven
        at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(Su
        at sun.awt.dnd.SunDropTargetEvent.dispatch(SunDropTargetEvent.java:29)
        at java.awt.Component.dispatchEventImpl(Component.java:3826)
        at java.awt.Container.dispatchEventImpl(Container.java:2024)
        at java.awt.Component.dispatchEvent(Component.java:3803)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212
        at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:400
        at java.awt.LightweightDispatcher.processDropTargetEvent(Container.java:
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3817)
        at java.awt.Container.dispatchEventImpl(Container.java:2010)
        at java.awt.Window.dispatchEventImpl(Window.java:1774)
        at java.awt.Component.dispatchEvent(Component.java:3803)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

EVALUATION This has already been fixed for Mustang by the fix for 4468566. TreeDropTargetListener has been completely removed with the re-architecture of Swing's drop support. It is worth mentioning that this bug has been filed before as 4760426. It is important to note that it will only occur after the UI has been switched on the JTree in question. If the UI is never changed (or the Look and Feel is not switched), this problem will not occur.