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

javax.swing.UIDefaults does not comply with Collection API

XMLWordPrintable



      Name: jk109818 Date: 02/20/2003


      FULL PRODUCT VERSION :
      java version "1.4.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
      Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)



      FULL OPERATING SYSTEM VERSION :
      Windows NT Version 4.0


      A DESCRIPTION OF THE PROBLEM :
      The javax.swing.UIDefaults class does not comply with the
      Java Collection API:

      1. Only a real subset of the key set gives back the correct
      values.

      2. Using an enumeration on the UIDefaults' keys does not
      return every key in the hashtable.

      3. Requesting the UIDefaults' key set iterator returns an
      empty one.

      The fact that UIDefaults *IS* a Hashtable and therefore a Map means that is
      must comply with the Map contract, in particular the contract of keySet(),
      values() and entrySet().

      Let's consider the keySet() method. It's contract states that the method
      "Returns a set view of the keys contained in this map." This means that if I
      can call get(xyz) on the Map and this returns an Object, then xyz should
      also be included in the result of keySet(). This is not the case for the
      UIDefaults class.

      The problem is that you override the get() method without overriding the
      three methods mentioned above.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the demo application listed in the source code
      section.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      I perform three tests:

      1. Copying the UIDefaults table to another one and looking
      up an arbitrary property in each hashtable. Expected output
      is "Yes Yes", the actual output is "Yes null" (notice that
      the property I am using is a resource bundle property).

      2. Iterating over the UIDefaults' key set:
      Expected result: A listing of each key in the UIDefaults
      hashtable.
      Actual result: No output, i.e. the for-loop is skipped.

      3. Iterating over the UIDefaults' keys using an Enumerator:
      Expected result: the same as in 2.
      Actual result: all properties except for resource bundle
      properties

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.util.*;
      import java.awt.*;

      public class UIDefaultsTest
      {
        public static void main(String[] args)
        {
          UIDefaults defaults = UIManager.getDefaults();
          Hashtable table = new Hashtable();

          table.putAll( defaults );

          System.out.println( defaults.get( "OptionPane.yesButtonText" ));
          System.out.println( table.get( "OptionPane.yesButtonText" ));

          System.out.println("#########################");

          for( Iterator iter = defaults.keySet().iterator(); iter.hasNext(); ) {
            System.out.println( iter.next() );
          }

          System.out.println("-------------------------");

          for( Enumeration enum = defaults.keys(); enum.hasMoreElements(); ) {
            System.out.println( enum.nextElement() );
          }
        }
      }

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

      CUSTOMER WORKAROUND :
      None, because there is no way to access the private members
      'private Vector resourceBundles' and
      'private Map resourceCache'
      (Review ID: 167168)
      ======================================================================

            Unassigned Unassigned
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: