JDK-4176094 : Incompatible changes in java.util Properties and Hashtable
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 1998-09-24
  • Updated: 2021-03-03
  • Resolved: 1998-09-24
Related Reports
Relates :  
Relates :  
Description

Name: tb29552			Date: 09/24/98


The changes to Properties and Hashtable breaks old code -
unnecessarily imho.

1. Properties.put(Object, Object) no longer supports anything that is not a
String, which means that a Properties no longer is a Hashtable. Anyone
using the Properties class for the extra convenience of the getProperty
method for getting Strings will get into trouble. 

The new method may or may not be a good thing in itself - but I don't
see why it is important enough to break old code.

2. The extensions to Hashtable means that old code relying on subclassing
Hashtable, e.g. in order to monitor changes in the table, will no longer work.
The reason is that a number of new methods in Hashtable (like entrySet())
modify the internal data of the Hashtable directly, rather than using the
old API (get, put, remove, etc.).

If subclassing of Hashtable, Properties, etc. wasn't allowed, they should
have been final.
(Review ID: 37603)
======================================================================

Comments
EVALUATION The restriction that Properties only permits String keys is not new in 1.2. The first sentence in Section 21.6 of the Java Language Specification (which describes the 1.0 APIs) says "A Properties is a kind of Hashtable with two functionality extensions and a restriction that keys and elements must be strings." Thus, it was a BUG that Sun's JDK permitted non-String keys and elements. Having said that, we backed out of our decision to enforce the spec, and enshrined the bug in the spec; thus you'll always be able to use non-String objects in your Properties. However, its bad style to take advantage of this: once you've inserted such an Object, the save/load functionality will no longer work. joshua.bloch@Eng 1998-09-24
24-09-1998