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 :  
Description
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
http://balui.sfbay/kits/oriondev/main/Build050713_14/installers/jstudio_ent8_ea-win.exe
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 :

java.lang.NullPointerException
        at javax.swing.plaf.basic.BasicTreeUI$TreeDropTargetListener.restoreComp
onentState(BasicTreeUI.java:3075)
        at javax.swing.plaf.basic.BasicDropTargetListener.dragExit(BasicDropTarg
etListener.java:252)
        at javax.swing.TransferHandler$SwingDropTarget.dragExit(TransferHandler.
java:601)
        at sun.awt.dnd.SunDropTargetContextPeer.processExitMessage(SunDropTarget
ContextPeer.java:366)
        at sun.awt.dnd.SunDropTargetContextPeer.access$700(SunDropTargetContextP
eer.java:53)
        at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchExitEven
t(SunDropTargetContextPeer.java:799)
        at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(Su
nDropTargetContextPeer.java:733)
        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
9)
        at java.awt.LightweightDispatcher.processDropTargetEvent(Container.java:
3955)
        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
read.java:242)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

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

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

Comments
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.
15-08-2005