JDK-4988920 : java.util.Properties should extend parameterized HashMap
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-02-04
  • Updated: 2016-05-18
  • Resolved: 2004-02-05
Related Reports
Relates :  
Relates :  
Description

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) 
======================================================================

Comments
EVALUATION Unfortunately, Properties cannot be parameterized with String, as it is legal (though strongly discouraged) to use non-String keys and values in a Properties instance, and some people actually depend on that behavior. Compatibility requirements dictate that we leave this class as it stands. (We could technically <Object,Object> but this isn't worth doing.) ###@###.### 2004-02-05
05-02-2004