JDK-4264897 : JTree can not handle a null-value returned by TreeMode.getRoot
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.8,1.2.0,1.2.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 1999-08-23
  • Updated: 2000-02-24
  • Resolved: 2000-02-24
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.
Other
1.4.0 merlinFixed
Related Reports
Duplicate :  
Description

Name: wl91122			Date: 08/23/99


Sorry, the last mail was not complete. Here is the complete version:

See the NullModel following. According to the documentation of the method getRoot of
TreeModel a null as a return-value is allowed, but the tree does not handle this
case correct.
I detected this error in a Swing1.1 release and in the JDK1.2 release.
A Swing 1.0 version does not have the bug.



SourceCode:
------------------------------>
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;


class NullModel implements TreeModel {
	public void addTreeModelListener(TreeModelListener l)           {              }
	public Object getChild(Object parent, int index)                { return null; }
	public int getChildCount(Object parent)                         { return 0;    }
	public int getIndexOfChild(Object parent, Object child)         { return 0;    }
	public Object getRoot()                                         { return null; }
	public boolean isLeaf(Object node)                              { 
		System.out.println("Asked for leafs: " + node);
		return true; }
	public void removeTreeModelListener(TreeModelListener l)        {              }
	public void valueForPathChanged(TreePath path, Object newValue) {              }
}


public class TreeBug {

	public TreeBug() {

		JTree tree = new JTree(new NullModel());

		JFrame frame = new JFrame();
		Container c = frame.getContentPane();
		c.setLayout(new BorderLayout());
		c.add(new JScrollPane(tree), BorderLayout.CENTER);

		frame.setSize(200, 300);
		frame.show(); 
	}

	public static void main(String[] args) { new TreeBug(); } 
}
<------------------------------

Output
------------------------------>
Asked for leafs: null
Exception in thread "main" java.lang.IllegalArgumentException: path in TreePath must be non null.
        at javax.swing.tree.TreePath.<init>(TreePath.java:71)
        at javax.swing.tree.VariableHeightLayoutCache.rebuild(Compiled Code)
        at javax.swing.tree.VariableHeightLayoutCache.setModel(VariableHeightLayoutCache.java:96)
        at javax.swing.plaf.basic.BasicTreeUI.setModel(BasicTreeUI.java:302)
        at javax.swing.plaf.basic.BasicTreeUI$PropertyChangeHandler.propertyChange(BasicTreeUI.java:
2578)
        at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(Compiled Code)
        at javax.swing.JComponent.firePropertyChange(JComponent.java:2924)
        at javax.swing.JTree.setModel(JTree.java:642)
        at javax.swing.JTree.<init>(JTree.java:460)
        at TreeBug.<init>(TreeBug.java:23)
        at TreeBug.main(TreeBug.java:34)
^C
<-----------------------------
(Review ID: 94240) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin merlin-beta FIXED IN: merlin merlin-beta INTEGRATED IN: merlin
14-06-2004

WORK AROUND Name: wl91122 Date: 08/23/99 see last mail ======================================================================
11-06-2004

EVALUATION As this has been documented for some time now, and worked at some point, it should work. It will require a number of tweaks to the layout cache classes, and possible to BasicTreeUI. scott.violet@eng 1999-09-17 The necessary tweaks have been to DefaultTreeModel, FixedHeightCache VariableHeightCache and JTree to allow for a null root. scott.violet@eng 2000-02-02
17-09-1999