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

Synopsis JList getModel() doesn't return a sub-class of AbstractListModel

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 6
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_02"
      Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_02-b06, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP SP3

      A DESCRIPTION OF THE PROBLEM :
      Originally bug 4801718. The problem has re-occured in the particular build shown above.

      I have a project which was left in a working state in March 2008 and when I returned to it July 2008 after (presumably) updates have been automatically applied to my JRE/JDK it is no longer working

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a class that extends JList - call the JList default constructor with super() then a simple method such as

          public DefaultListModel getDefaultListModel()
          {
              return (DefaultListModel) getModel();
          }

      will result in a class cast exception javax.swing.JList$3 cannot be cast to DefaultListModel

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      getModel() should return a form of AbstractListModel (specifically ListModel in the JList source)
      ACTUAL -
      Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JList$3 cannot be cast to javax.swing.DefaultListModel


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import javax.swing.DefaultListModel;
      import javax.swing.JList;

      /**
       * Steps to reproduce re occurred bug 4801718
       * @author LLINCOLN
       */
      public class BugRep extends JList{

          public BugRep()
          {
              super();
          }

          public DefaultListModel getDefaultModel()
          {
              return (DefaultListModel) getModel();
          }

          public static void main(String[] args)
          {
              BugRep rep = new BugRep();
              rep.getDefaultModel();
          }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      call super(new DefaultListModel()); in the constructor.

            Unassigned Unassigned
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: