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)
======================================================================
- relates to
-
JDK-8157123 java.util.Properties class is violating the Liskov's Substitution Principle (LSP)
-
- Closed
-
-
JDK-6368455 (props) Properties should extend Hashtable<String,String> not Hashtable<Object,Object>
-
- Closed
-