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

javax.swing.tree.TreeNode.children() has wrong Enumeration Generic returntype

XMLWordPrintable

    • b59
    • x86
    • linux



      Name: js151677 Date: 06/21/2004


      FULL PRODUCT VERSION :
      ...> java -version
      java version "1.5.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b55)
      Java HotSpot(TM) Server VM (build 1.5.0-beta3-b55, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      ...> uname -a
      Linux riedquat 2.4.20-64GB-SMP #1 SMP Fri Apr 2 19:10:22 UTC 2004 i686 unknown unknown GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      The ReturnType of javax.swing.tree.TreeNode has been changed to use Generics.
      But instead of Enumeration<TreeNode> it should be Enumeration<? extends TreeNode>

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to compile the source below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Source compiles
      ACTUAL -
      Source does not compile because the return type of javax.swing.tree.TreeNode.children() is too specific. It should be Enumeration<? extends TreeNode>, but it is Enumeration<TreeNode> which disables programmers from returning Enumerations that's elements are guaranteed to be of a certain subtype of TreeNode.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Enumeration;
      import javax.swing.tree.TreeNode;

      import javax.swing.tree.TreeNode;

      public class MyNode implements TreeNode {

          public Enumeration<MyNode> children() {
              return null;
          }
          public boolean getAllowsChildren() {
              return true;
          }
          public MyNode getChildAt(int childIndex) {
              return null;
          }
          public int getChildCount() {
              return 0;
          }
          public int getIndex(TreeNode node) {
              return -1;
          }
          public TreeNode getParent() {
              return null;
          }
          public boolean isLeaf() {
              return true;
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Since the error is in the published sources, it's simple (at least this should be simple for any serious Java developer):
      1. Apply the following patch
      2. Compile TreeNode.java
      3. Put it in a Jar
      4. Put that Jar in jre/lib/endorsed

      *** TreeNode.java 2004-06-20 21:57:21.000000000 +0200
      --- /dist/opt/sun/j2sdk/se/latest/src/javax/swing/tree/TreeNode.java 2004-06-09 09:25:59.000000000 +0200
      ***************
      *** 64,68 ****
            /**
             * Returns the children of the receiver as an <code>Enumeration</code>.
             */
      ! Enumeration<? extends TreeNode> children();
        }
      --- 64,68 ----
            /**
             * Returns the children of the receiver as an <code>Enumeration</code>.
             */
      ! Enumeration<TreeNode> children();
        }
      (Incident Review ID: 280755)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: