Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4255140

DefaultTreeModel.getListeners(Class) throws exception

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description



      Name: sdC67446 Date: 07/19/99


      The method
          public EventListener[] getListeners(Class listenerType)
      of class javax.swing.tree.DefaultTreeModel
      throws unspecified ClassCastException for all input parameters except
      TreeModelListener.class.
      The method should return null/empty array or documentation should be
      updated.

      The doc says:
      --------------------------------------------------
      ublic EventListener[] getListeners(Class listenerType)

            Return an array of all the listeners of the given type that were
            added to this model.
            Since:
                  1.3

      The test demonstrating the bug:
      -----------------Test.java------------------------
      import javax.swing.tree.*;
      import javax.swing.event.*;
      import java.util.*;

      public class Test {

          public static class DummyTreeModelListener implements TreeModelListener {
          
              public void treeNodesChanged(TreeModelEvent e) {}
              public void treeNodesInserted(TreeModelEvent e) {}
              public void treeNodesRemoved(TreeModelEvent e) {}
              public void treeStructureChanged(TreeModelEvent e) {}
              public boolean isListening(DefaultTreeModel model) {
                  return false;
              }
          }

          public static void main(String[] args) {
              DefaultMutableTreeNode root =
                  new DefaultMutableTreeNode(new Integer(1975));
              DefaultTreeModel model = new DefaultTreeModel(root);
              
              DummyTreeModelListener l = new DummyTreeModelListener();
              
              System.out.println("- 1 -");
              System.out.println(model.getListeners(TreeModelListener.class));
              System.out.println("- 2 -");
              System.out.println(model.getListeners(Integer.class));
          }
      }
      ---------Output from the test---------------------
      - 1 -
      [Ljavax.swing.event.TreeModelListener;@54a10fb9
      - 2 -
      Exception in thread "main" java.lang.ClassCastException: java.lang.Object
              at javax.swing.event.EventListenerList.getListeners(EventListenerList.java, Compiled Code)
              at javax.swing.tree.DefaultTreeModel.getListeners(DefaultTreeModel.java, Compiled Code)
              at Test.main(Test.java, Compiled Code)
      --------------------------------------------------
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            sharonz Sharon Zakhour (Inactive)
            Reporter:
            dsvsunw Dsv Dsv (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: