United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4264897 : JTree can not handle a null-value returned by TreeMode.getRoot

Details
Type:
Bug
Submit Date:
1999-08-23
Status:
Resolved
Updated Date:
2000-02-24
Project Name:
JDK
Resolved Date:
2000-02-24
Component:
client-libs
OS:
generic
Sub-Component:
javax.swing
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.1.8,1.2.0,1.2.2
Fixed Versions:
1.4.0 (merlin)

Related Reports
Duplicate:

Sub Tasks

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


                                     
2004-06-14
WORK AROUND



Name: wl91122			Date: 08/23/99


see last mail
======================================================================
                                     
2004-06-11
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
                                     
1999-09-17



Hardware and Software, Engineered to Work Together