Bug 27651 - ClassCastException via javax.swing.tree.TreePath.isDescendant()
Summary: ClassCastException via javax.swing.tree.TreePath.isDescendant()
Status: RESOLVED FIXED
Alias: None
Product: classpath
Classification: Unclassified
Component: swing (show other bugs)
Version: unspecified
: P3 normal
Target Milestone: 0.92
Assignee: Roman Kennke
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-17 22:25 UTC by pere
Modified: 2006-06-06 15:43 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description pere 2006-05-17 22:25:46 UTC
When running openjump, trying to fetch a map using WMS, I get this
exception:

java.lang.ClassCastException: javax/swing/JTree$DynamicUtilTreeNode
   at com.vividsolutions.jump.workbench.ui.plugin.wms.MapLayerTreeModel$LayerNode.equals(MapLayerTreeModel.java:123)
   at javax.swing.tree.TreePath.isDescendant(TreePath.java:269)
   at javax.swing.JTree.getExpandedDescendants(JTree.java:2859)
   at javax.swing.plaf.basic.BasicTreeUI.updateExpandedDescendants(BasicTreeUI.java:1118)
   at javax.swing.plaf.basic.BasicTreeUI.installUI(BasicTreeUI.java:1357)
   at javax.swing.plaf.metal.MetalTreeUI.installUI(MetalTreeUI.java:107)
   at javax.swing.JComponent.setUI(JComponent.java:3045)
   at javax.swing.JTree.setUI(JTree.java:1622)
   at javax.swing.JTree.updateUI(JTree.java:1630)
   at javax.swing.JTree.setModel(JTree.java:1910)
   at com.vividsolutions.jump.workbench.ui.addremove.TreeAddRemoveList.setModel(TreeAddRemoveList.java:85)
   at com.vividsolutions.jump.workbench.ui.plugin.wms.MapLayerPanel.init(MapLayerPanel.java:314)
   at com.vividsolutions.jump.workbench.ui.plugin.wms.MapLayerWizardPanel.enteredFromLeft(MapLayerWizardPanel.java:97)
   at com.vividsolutions.jump.workbench.ui.wizard.WizardDialog.nextButton_actionPerformed(WizardDialog.java:286)
   at com.vividsolutions.jump.workbench.ui.wizard.WizardDialog$3.actionPerformed(WizardDialog.java:213)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1099)
   at javax.swing.AbstractButton$1.actionPerformed(AbstractButton.java:1909)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:298)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:403)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:188)
   at java.awt.Component.processMouseEvent(Component.java:3105)
   at java.awt.Component.processEvent(Component.java:2964)
   at java.awt.Container.processEvent(Container.java:914)
   at java.awt.Component.dispatchEventImpl(Component.java:5033)
   at java.awt.Container.dispatchEventImpl(Container.java:1741)
   at java.awt.Component.dispatchEvent(Component.java:2322)
   at java.awt.LightweightDispatcher.handleMouseEvent(LightweightDispatcher.java:234)
   at java.awt.LightweightDispatcher.dispatchEvent(LightweightDispatcher.java:116)
   at java.awt.Container.dispatchEventImpl(Container.java:1731)
   at java.awt.Window.dispatchEventImpl(Window.java:642)
   at java.awt.Component.dispatchEvent(Component.java:2322)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:474)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:95)
java.lang.ClassCastException: javax/swing/JTree$DynamicUtilTreeNode
   at com.vividsolutions.jump.workbench.ui.plugin.wms.MapLayerTreeModel$LayerNode.equals(MapLayerTreeModel.java:123)
   at javax.swing.tree.TreePath.isDescendant(TreePath.java:269)
   at javax.swing.JTree.getExpandedDescendants(JTree.java:2859)
   at javax.swing.plaf.basic.BasicTreeUI.updateExpandedDescendants(BasicTreeUI.java:1118)
   at javax.swing.plaf.basic.BasicTreeUI.installUI(BasicTreeUI.java:1357)
   at javax.swing.plaf.metal.MetalTreeUI.installUI(MetalTreeUI.java:107)
   at javax.swing.JComponent.setUI(JComponent.java:3045)
   at javax.swing.JTree.setUI(JTree.java:1622)
   at javax.swing.JTree.updateUI(JTree.java:1630)
   at javax.swing.JTree.setModel(JTree.java:1910)
   at com.vividsolutions.jump.workbench.ui.addremove.TreeAddRemoveList.setModel(TreeAddRemoveList.java:85)
   at com.vividsolutions.jump.workbench.ui.plugin.wms.MapLayerPanel.init(MapLayerPanel.java:314)
   at com.vividsolutions.jump.workbench.ui.plugin.wms.MapLayerWizardPanel.enteredFromLeft(MapLayerWizardPanel.java:97)
   at com.vividsolutions.jump.workbench.ui.wizard.WizardDialog.nextButton_actionPerformed(WizardDialog.java:286)
   at com.vividsolutions.jump.workbench.ui.wizard.WizardDialog$3.actionPerformed(WizardDialog.java:213)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1099)
   at javax.swing.AbstractButton$1.actionPerformed(AbstractButton.java:1909)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:298)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:403)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:188)
   at java.awt.Component.processMouseEvent(Component.java:3105)
   at java.awt.Component.processEvent(Component.java:2964)
   at java.awt.Container.processEvent(Container.java:914)
   at java.awt.Component.dispatchEventImpl(Component.java:5033)
   at java.awt.Container.dispatchEventImpl(Container.java:1741)
   at java.awt.Component.dispatchEvent(Component.java:2322)
   at java.awt.LightweightDispatcher.handleMouseEvent(LightweightDispatcher.java:234)
   at java.awt.LightweightDispatcher.dispatchEvent(LightweightDispatcher.java:116)
   at java.awt.Container.dispatchEventImpl(Container.java:1731)
   at java.awt.Window.dispatchEventImpl(Window.java:642)
   at java.awt.Component.dispatchEvent(Component.java:2322)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:474)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:95)

The throwing code in MapLayerTreeModel.java:123 is this cast to
LayerNode:

  public class MapLayerTreeModel extends DefaultTreeModel {
      [...]
      public static class LayerNode implements TreeNode, Comparable {
      [...]
          public boolean equals(Object o) {
              //Needed for the #contains check in MapLayerPanel, as well as #getIndex. [Jon Aquino]
              LayerNode other = (LayerNode) o;
  
              return layer == other.layer;
          }
      [...]
      }
  }

I run openjump in Debian using this command line, using the CVS
verison of GNU Classpath:

  JAVACMD="/usr/bin/jamvm" \
    JAVA_ARGS="-Dgnu.java.awt.peer.gtk.Graphics=Graphics2D -Xms256M -Xmx256M" \
    openjump
Comment 1 Andrew Pinski 2006-05-17 22:29:27 UTC
Subject: Re:  New: ClassCastException via

> 
> When running openjump, trying to fetch a map using WMS, I get this
> exception:
> 
> java.lang.ClassCastException: javax/swing/JTree$DynamicUtilTreeNode
>    at
> com.vividsolutions.jump.workbench.ui.plugin.wms.MapLayerTreeModel$LayerNode.equals(MapLayerTreeModel.java:123)
>    at javax.swing.tree.TreePath.isDescendant(TreePath.java:269)
.....
> The throwing code in MapLayerTreeModel.java:123 is this cast to
> LayerNode:
> 
>   public class MapLayerTreeModel extends DefaultTreeModel {
>       [...]
>       public static class LayerNode implements TreeNode, Comparable {
>       [...]
>           public boolean equals(Object o) {
>               //Needed for the #contains check in MapLayerPanel, as well as
> #getIndex. [Jon Aquino]
>               LayerNode other = (LayerNode) o;

I don't think this is a bug in classpath.  equals can take any object type so
this exception is correct.

-- Pinski
Comment 2 pere 2006-05-17 22:41:35 UTC
> I don't think this is a bug in classpath.  equals can take any object type so
> this exception is correct.

Well, openjump work just fine with SUN Java, so if the bug isn't in Classpath,
it seem to be missing a bug that is in SUN Java. :)
Comment 3 Roman Kennke 2006-05-18 08:07:08 UTC
OpenJump seems to assume an Sun-implementation-specific type in its equals() method (presumably some subtype of TreeNode). I don't think that we can fix it. Maybe you could find out what type that is and we'll see if we can handle it.
Comment 4 david.gilbert 2006-05-18 09:36:54 UTC
>       public static class LayerNode implements TreeNode, Comparable {
>       [...]
>           public boolean equals(Object o) {
>               //Needed for the #contains check in MapLayerPanel, as well as
> #getIndex. [Jon Aquino]
>               LayerNode other = (LayerNode) o;
> 
>               return layer == other.layer;
>           }
>       [...]
>       }
>   }

So TreeNode.equals(LayerNode) presumably is OK, but LayerNode.equals(TreeNode) will throw a ClassCastException.  This made me wonder if our implementation of TreePath.isDescendant() has the equals() test around the opposite way to the reference implementation.  So I wrote a Mauve test to check this implementation detail...but (unfortunately) it shows that this isn't the problem (the checks pass on both GNU Classpath and Sun's JRE 1.5.0_06).  Anyway, I'll commit the test to Mauve now in case anyone wants to look at it - the file is:

gnu/testlet/javax/swing/tree/TreePath/PR27651.java
Comment 5 Roman Kennke 2006-06-06 15:43:36 UTC
Fixed in CVS.
Comment 6 cvs-commit@developer.classpath.org 2006-06-06 15:54:56 UTC
Subject: Bug 27651

CVSROOT:	/cvsroot/classpath
Module name:	classpath
Changes by:	Roman Kennke <rabbit78>	06/06/06 15:34:56

Modified files:
	javax/swing    : JTree.java 
	.              : ChangeLog 

Log message:
	2006-06-06  Roman Kennke  <kennke@aicas.com>
	
		PR 27651
		* javax/swing/JTree.java
		(JTree(TreeModel)): Call updateUI() before setModel().
		(setModel): Don't call updateUI here.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/classpath/javax/swing/JTree.java?cvsroot=classpath&r1=1.67&r2=1.68
http://cvs.savannah.gnu.org/viewcvs/classpath/ChangeLog?cvsroot=classpath&r1=1.7680&r2=1.7681

Patches:

Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.7680
retrieving revision 1.7681
diff -u -b -r1.7680 -r1.7681
--- ChangeLog	6 Jun 2006 15:27:56 -0000	1.7680
+++ ChangeLog	6 Jun 2006 15:34:56 -0000	1.7681
@@ -1,3 +1,10 @@
+2006-06-06  Roman Kennke  <kennke@aicas.com>
+
+	PR 27651
+	* javax/swing/JTree.java
+	(JTree(TreeModel)): Call updateUI() before setModel().
+	(setModel): Don't call updateUI here.
+
 2006-06-06  Lillian Angel  <langel@redhat.com>
 	
 	* native/plugin/gcjwebplugin.cc:
@@ -20,6 +27,13 @@
 
 2006-06-06  Roman Kennke  <kennke@aicas.com>
 
+	PR 27651
+	* javax/swing/JTree.java
+	(JTree(TreeModel)): Call updateUI() before setModel().
+	(setModel): Don't call updateUI here.
+
+2006-06-06  Roman Kennke  <kennke@aicas.com>
+
 	PR 27523
 	* javax/swing/MenuSelectionManager.java
 	(processKeyEvent): Added check to avoid