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

NPE drag-n-drop a swing JTree node (from a JPanel) onto an empty JPanel

XMLWordPrintable

      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)

            shickeysunw Shannon Hickey (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: