-
Bug
-
Resolution: Fixed
-
P4
-
1.2.2
-
merlin
-
generic
-
generic
Name: krT82822 Date: 11/17/99
11/17/99 eval1127@eng -- may be related to # 4179889...
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)
#########
At JTree, the getPathForLocation method can throw a null pointer exception!
Exception occurred during event dispatching:
java.lang.NullPointerException:
at javax.swing.JTree.getPathForLocation(JTree.java:1520)
at javax.swing.JTree.getRowForLocation(JTree.java:1539)
at javax.swing.JTree.getToolTipText(JTree.java:898)
at javax.swing.ToolTipManager.mouseMoved(ToolTipManager.java:476)
at java.awt.Component.processMouseMotionEvent(Component.java:3201)
at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:1852)
at java.awt.Component.processEvent(Component.java:3003)
at java.awt.Container.processEvent(Container.java:990)
at java.awt.Component.dispatchEventImpl(Component.java:2394)
at java.awt.Container.dispatchEventImpl(Container.java:1035)
at java.awt.Component.dispatchEvent(Component.java:2307)
at java.awt.LightweightDispatcher.retargetMouseEvent
(Container.java:2043)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1855)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1730)
at java.awt.Container.dispatchEventImpl(Container.java:1022)
at java.awt.Window.dispatchEventImpl(Window.java:749)
at java.awt.Component.dispatchEvent(Component.java:2307)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:287)
at java.awt.EventDispatchThread.pumpOneEvent
(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:92)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:83)
The problem is that it does a "Rectangle pathBouds=getPathBounds" and then uses
the "pathBounds" reference pointer without checking whether it's null or not
#########
public TreePath getPathForLocation(int x, int y) {
TreePath closestPath = getClosestPathForLocation(x, y);
if(closestPath != null) {
Rectangle pathBounds = getPathBounds(closestPath);
if(x >= pathBounds.x && x < (pathBounds.x + pathBounds.width) &&
y >= pathBounds.y && y < (pathBounds.y + pathBounds.height))
return closestPath;
}
return null;
}
##################
indeed the getPathBounds() method's comments state it does returns null in the
following case: "if any component in the path is hidden (under a collapsed
parent)"
/**
* Returns the Rectangle that the specified node will be drawn
* into. Returns null if any component in the path is hidden
* (under a collapsed parent).
* <p>
* Note:<br>
* This method returns a valid rectangle, even if the specified
* node is not currently displayed.
*
* @param path the TreePath identifying the node
* @return the Rectangle the node is drawn in, or null
*/
public Rectangle getPathBounds(TreePath path) {
TreeUI tree = getUI();
if(tree != null)
return tree.getPathBounds(this, path);
return null;
}
(Review ID: 97997)
======================================================================