Name: skT88420 Date: 06/18/99
The javax.swing.tree.TreeModel interface comments indicate
that null is a valid result for the getRoot() method -- it
means that the tree contains no nodes.
However, the setModel(TreeModel) method of javax.swing.JTree
assumes that the result of getRoot() is always non-null and
passes the null to the single-arg constructor of
javax.swing.tree.TreePath. The TreePath constructor throws
a NullPointerException, and setModel fails.
Personally, I'd like to see the getDefaultTreeModel method
return a truly empty Tree, with a null root node. The "colors"
and "sports" tree used now is not appropriate for any real
application, so the model must alway be set explicitly before
the tree is displayed...
(Review ID: 84501)
======================================================================
Name: krT82822 Date: 08/27/99
The documentation for TreeModel explicitly states (in the description of getRoot() ) that a TreeModel may return null to indicate that a tree has no nodes.
However, the implementation of JTree raises an IllegalArgumentException if TreeModel.getRoot() actually returns null.
The problem seems to be in javax.swing.tree.VariableHeightLayoutCache.rebuild(); here is a backtrace of the exception:
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(VariableHeightLayo
utCache.java:663)
at javax.swing.tree.VariableHeightLayoutCache.setModel(VariableHeightLay
outCache.java:96)
at javax.swing.plaf.basic.BasicTreeUI.setModel(BasicTreeUI.java:302)
at javax.swing.plaf.basic.BasicTreeUI$PropertyChangeHandler.propertyChan
ge(BasicTreeUI.java:2596)
at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(Swing
PropertyChangeSupport.java:154)
at javax.swing.JComponent.firePropertyChange(JComponent.java:3023)
at javax.swing.JTree.setModel(JTree.java:642)
at javax.swing.JTree.<init>(JTree.java:460)
(Review ID: 94535)
======================================================================