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)
======================================================================