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

[macosx] UIDefaults.keys() different size than UIDefaults.keySet()

    Details

    • Subcomponent:
    • Resolved In Build:
      b16
    • CPU:
      x86
    • OS:
      os_x

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_66"
      Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Darwin Chrystas-Air.home 15.0.0 Darwin Kernel Version 15.0.0: Sat Sep 19 15:53:46 PDT 2015; root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      The number of items enumerated over by UIDefaults.keys() is different than the number of items included in UIDefaults.keySet(). I expect these to be the same.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      This is demonstrated by compiling and running the following code:

      import java.util.Enumeration;
      import javax.swing.UIManager;

      public class UIManagerTest {

          public static void main(String[] args) {
              int ie = 0;
              int is = 0;
              Enumeration e = UIManager.getDefaults().keys();
              while (e.hasMoreElements()) {
                  ie = ie + 1;
                  System.out.println("Enumerated: " + e.nextElement());
              }
              for (Object k : UIManager.getDefaults().keySet()) {
                  is = is + 1;
                  System.out.println("Set: " + k);
              }
              System.out.println("UIDefaults.keys() contains " + ie + " elements.");
              System.out.println("UIDefaults.keySet() contains " + is + " elements.");
          }

      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I was expecting the last two lines to read:

      UIDefaults.keys() contains 719 elements.
      UIDefaults.keySet() contains 719 elements.
      ACTUAL -
      The last two lines read:

      UIDefaults.keys() contains 719 elements.
      UIDefaults.keySet() contains 0 elements.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Enumeration;
      import javax.swing.UIManager;

      public class UIManagerTest {

          public static void main(String[] args) {
              int ike = 0;
              int iks = 0;
              Enumeration e = UIManager.getDefaults().keys();
              while (e.hasMoreElements()) {
                  ike = ike + 1;
                  System.out.println("Enumerated: " + e.nextElement());
              }
              for (Object k : UIManager.getDefaults().keySet()) {
                  iks = iks + 1;
                  System.out.println("Set: " + k);
              }
              System.out.println("UIDefaults.keys() contains " + ike + " elements.");
              System.out.println("UIDefaults.keySet() contains " + iks + " elements.");
          }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      The workaround is to not use enhanced for loops or streams to iterate over the keys in UIDefaults.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                trebari Tejpal Rebari
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: