JDK-6671481 : NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u3,7u6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,windows_7,windows_8
  • CPU: x86
  • Submitted: 2008-03-05
  • Updated: 2013-06-26
  • Resolved: 2013-04-26
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.
JDK 6 JDK 7 JDK 8
6u60 b01Fixed 7u40Fixed 8Fixed
Description
NPE in BasicTreeUI:

java.lang.NullPointerException
        at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(BasicTreeUI.java:3501)
        at javax.swing.plaf.basic.BasicTreeUI$Handler.mouseReleasedDND(BasicTreeUI.java:3571)
        at javax.swing.plaf.basic.BasicTreeUI$Handler.mouseReleased(BasicTreeUI.java:3559)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
        at java.awt.Component.processMouseEvent(Component.java:6041)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5806)
        at java.awt.Container.processEvent(Container.java:2058)
        at java.awt.Component.dispatchEventImpl(Component.java:4413)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.LightweightDispatcher.retargetMouseEvent(LightweightDispatcher.java:4322)
        at java.awt.LightweightDispatcher.processMouseEvent(LightweightDispatcher.java:3986)
        at java.awt.LightweightDispatcher.dispatchEvent(LightweightDispatcher.java:3916)
        at java.awt.Container.dispatchEventImpl(Container.java:2102)
        at java.awt.Window.dispatchEventImpl(Window.java:2440)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at org.netbeans.core.TimeableEventQueue.dispatchEvent(TimeableEventQueue.java:104)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

I examined the code and it looks like getPathBounds(tree, pressedPath) returns null (don't know why and how) and then NPE arises:

                Rectangle bounds = getPathBounds(tree, pressedPath);

line 3501: NPE:     if(e.getY() >= (bounds.y + bounds.height)) {
                    return;
                }


Happens in NetBeans IDE, original issue is here:
http://www.netbeans.org/issues/show_bug.cgi?id=126170

Nice summarization of when error appeared to users can be seen here:
http://statistics.netbeans.org/analytics/detail.do?id=2534

Comments
I do not know steps to reproduce the issue, but the fixed issue 6505523 can shed light on this mysterious NPE. It is reproduced when drag is enabled and a node is removed by an expansion listener. The pressed path is stored in the BasicTreeUI during mouse pressed event. Then the expansion listener removes the path and the mouse released event checks the stored path by the getPathBounds() method and gets null (the path has been already removed).
26-11-2012

SQE is OK to defer this
19-11-2012

Justification: Deferred as failed in 6u3 - will work to resolve (Fix/Close - with SQE agreement) by the end of Dec/2012.
19-11-2012

Raising priority and adding 7u9 and 7u10 amongst affected versions. Even though the similar bug JDK-6505523 was closed fixed in 7u4 and 6u38, there are more duplicates gathering against NetBeans. See http://statistics.netbeans.org/exceptions/detail.do?id=2534 http://statistics.netbeans.org/exceptions/detail.do?id=193286
06-11-2012

EVALUATION I understand, it is difficult to fight with random and rarely reproducible bugs, we are in the same state here in NetBeans team. Unfortunately, I'm not able to produce test case for you - issue never happened on my machine and I don't know how to simulate it. However, in such situations "defensive" fix looks enough for me - if you are checking for null from getBounds on other places, just check once more, anything is better then exception. I know that it may just hide real source of error, but I don't have better idea, sorry.
19-03-2008

EVALUATION It is very difficult to work with a bug without any test case, There are two cases when BasicTreeUI.getPathBounds() can return null: if(tree != null && treeState != null) { return getPathBounds(path, tree.getInsets(), new Rectangle()); } return null; At least we need to know if the tree or treeState is null when NPE arises (runnable test case would be ideal) asked submitter for more information
14-03-2008