On Wed, 4 Nov 2026 22:57:02 GMT, errael <[email protected]> wrote:
> > I don't think we should go as far as to codify the current implementation
> > of `load()`
>
> Isn't that what this PR does?
We are specifying how the method behaves, ("load() replaces values for keys
already in the Properties").
But implementation details are not included ("load() adds key/value pairs to
the Properties by calling put()").
> Note javadoc currently says setProperty(String key, String value) Calls the
> Hashtable method put.
Yes, that is an example of the implementation having leaked into specification.
And how that can backfire because - _it's (now) wrong_!
In JDK 9 `Properties` was retrofitted in order to avoid deadlocks. Since then,
key/value data are stored in an internal `ConcurrentHashMap`, not in the
inherited `Hashtable`. So `Hastable.put()` is _not_ called. (Further info in
the [Release
Note](https://www.oracle.com/java/technologies/javase/9-all-relnotes.html#JDK-8029891)
and [JDK-8029891](https://bugs.openjdk.org/browse/JDK-8029891))
It would have been better (back in JDK 1.0, or whenever) to describe what
`setProperty()` does, without including this implementation detail (or, to
correct the spec at the time of 8029891). But this can be fixed up now, while
we're at it.
I would not generally recommend relying on the implementation calling a
particular overridable method as a way to customize behavior, e.g. to add
verification. (An exception would be cases where such support is specifically
called out.)
Today, an overridden `put()` happens to be called by `load()`, but a future
version may not work that way. And FWIW, `Properties.put()` is not called by
`Properties.putAll()`.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/33638#issuecomment-6839973434