JDK-8013571 : TreeModelEvent doesn't accept " null " for root as Javadoc specifies.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2013-04-04
  • Updated: 2014-11-17
  • Resolved: 2013-06-17
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.
JDK 8
8 b96Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
The javadoc says

 Notes:

    Like the insertNodeInto method in the DefaultTreeModel class, insertElementAt appends to the Vector when the index matches the size of the vector. So you can use insertElementAt(Integer, 0) even when the vector is empty.
        To create a node changed event for the root node, specify the parent and the child indices as null.



REGRESSION.  Last worked in version 7

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I have coded the following method to use in my TreeModel when I make changes to the root.  It is a DefaultMutableTreeNode, and I want to be able to use  " setUserObject(String) "  to change the title on the root.

private void rootChanged() {
model.fireTreeNodesChanged( tree, new Object[]{root}, null, new Object[]{ root} );
tree.repaint();
}

When I call this method, I see this exception:

Caused by: java.lang.IllegalArgumentException: Last path component must be non-null
at javax.swing.tree.TreePath.<init>(TreePath.java:105)
at javax.swing.event.TreeModelEvent.<init>(TreeModelEvent.java:131)
at javax.swing.tree.DefaultTreeModel.fireTreeNodesChanged(DefaultTreeModel.java:484)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The documentation says this will work.
ACTUAL -
The exception will cause problems in the application's behavior

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Caused by: java.lang.IllegalArgumentException: Last path component must be non-null
at javax.swing.tree.TreePath.<init>(TreePath.java:105)
at javax.swing.event.TreeModelEvent.<init>(TreeModelEvent.java:131)
at javax.swing.tree.DefaultTreeModel.fireTreeNodesChanged(DefaultTreeModel.java:484)

REPRODUCIBILITY :
This bug can be reproduced always.
Comments
javax/swing/JTree/8013571/Test8013571.java PASSED under JDK 8 b132 on MacOS, Linux, Solaris, Windows. Closed issue as Fixed/Verified.
11-03-2014

The compilable test case "TreeModelEventInitWithNull.java", which reproduces the issue described by the user is created and attached. To reproduce the issue this test case should be compiled and executed, the exception "java.lang.IllegalArgumentException: path in TreePath must be non null and not empty." with a corresponding stack trace should be seen in the console output.
30-04-2013

The issue is reproducible with JDK 7u21. I would like to note that the user who filed this bug did not present a compilable test case, also the user's code example does not correspond to his/her statements concerning the parameters which should be supplied to a constructor of "javax.swing.event.TreeModelEvent" class, because "new Object[]{root}" is passed instead of null as "path" parameter. However, I can conclude that there is a real discrepancy between the Java SE 7 API Specification and implementation in the following places: 1. Documentation: The constructor "javax.swing.event.TreeModelEvent.TreeModelEvent(Object source, Object[] path, int[] childIndices, Object[] children)". Discrepancy: Statement "To create a node changed event for the root node, specify the parent and the child indices as null." is false, because if null is passed as "path" parameter, an exception of the type "IllegalArgumentException" will always be thrown. 2. Documentation: The method "javax.swing.tree.DefaultTreeModel.fireTreeNodesChanged(Object source, Object[] path, int[] childIndices, Object[] children)". Discrepancy: Statement "use null to identify the root has changed" is false, because if null is passed as "path" parameter, an exception of the type "IllegalArgumentException" will always be thrown.
30-04-2013