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

java.util.Properties should extend parameterized HashMap

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 5.0
    • core-libs
    • x86
    • windows_xp



      Name: rl43681 Date: 02/04/2004


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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      java.util.Properties extends java.util.Hashtable without parameterization,
      giving it non-intuitive behavior when it is treated as a Map. If its superclass was parameterized with String for its key type and value type, it would behave as expected.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Save the sample as PropsBug.java.
      2. Compile using the command
      javac -deprecation -target 1.5 -source 1.5 -Xlint PropsBug.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compiles with no errors or warnings.
      ACTUAL -
      Compiles, but warns of unchecked method invocation.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      PropsBug.java:8: warning: unchecked method invocation: putAll(java.util.Map<? extends K,? extends V>) in java.util.Map is applied to (java.util.Properties)
          m.putAll(p);
           ^

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;

      public class PropsBug {
        static void main(String[] args) {
          Map<String, String> m = new HashMap<String, String>();
          Properties p = new Properties();

          m.putAll(p);
        }
      }

      ---------- END SOURCE ----------
      (Incident Review ID: 236531)
      ======================================================================

            jjb Josh Bloch
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: