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

Addition of generics to some Swing classes breaks existing code

    XMLWordPrintable

Details

    • b02
    • 9
    • generic
    • generic

    Description

      FULL PRODUCT VERSION :
      openjdk version "9-Ubuntu"
      OpenJDK Runtime Environment (build 9-Ubuntu+0-9b181-2)
      OpenJDK 64-Bit Server VM (build 9-Ubuntu+0-9b181-2, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux astoria 4.10.0-32-generic #36-Ubuntu SMP Tue Aug 8 12:10:06 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      The class "javax.swing.tree.DefaultMutableTreeNode" has gained generics on some protected fields which are for client usage. It contained raw Vector previously, now contains a Vector<TreeNode>.

      This breaks existing code horribly, as clients must use their own TreeNode extension, e.g. in the Electric VLSI tool here:
      https://sources.debian.net/src/electric/9.07%2Bdfsg-2/com/sun/electric/tool/user/ui/JobTree.java/#L50

      children = [..] new Vector<JobTreeNode>();

      Also the addition of generics to the "Enumeration children()" requires code changes, but not as horrible. Also left broken in the code example below.

      Perhaps this field should be <? extends TreeNode>? Or the class should be generic?

      REGRESSION. Last worked in version 8u144


      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      class MyNode implements TreeNode {
        public boolean isLeaf() { return false; }
        public TreeNode getParent() { return null; }
        public int getIndex(TreeNode node) { return 0; }
        public int getChildCount() { return 0; }
        public TreeNode getChildAt(int childIndex) { return null; }
        public boolean getAllowsChildren() { return false; }
        public Enumeration<?> children() { return null; }
      }

      class A extends DefaultMutableTreeNode {
        A() {
          children = new Vector<MyNode>();
        }
      }

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

      Attachments

        Issue Links

          Activity

            People

              prr Philip Race
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: