On Tue, 14 Sep 2021 20:34:21 GMT, Daniel Fuchs <dfu...@openjdk.org> wrote:

>> src/java.base/share/classes/java/util/Properties.java line 929:
>> 
>>> 927:             @SuppressWarnings("unchecked")
>>> 928:             var entries = new ArrayList<>(((Map<String, String>) (Map) 
>>> map).entrySet());
>>> 929:             entries.sort(Map.Entry.comparingByKey());
>> 
>> Since Properties can be subclassed and the `entrySet()` method overridden, 
>> should the set of entries to be sorted be taken from this.entrySet() instead 
>> of bypassing the public API?
>
> Hmm, so if someone has subclassed `Properties` and overridden `entrySet` for 
> the purpose of ordering entries, that trick will no longer work with the new 
> code. I wonder - should we sort entries only when the 
> `java.util.Properties.storeDate` is also defined and not empty? Or should we 
> simply state in the release notes that such tricks will no longer work?

I think we want the entries to be sorted by default; that is the most useful to 
the most people.
Checking for the overloaded method seems like trying too hard.
Changing the entrySet to return them sorted (always) would add overhead in a 
lot of cases but would allow a subclass to re-sort them as they see fit.
A half measure would be to sort only if the properties instance was not 
subclassed and spec it that way as an implementation detail.

-------------

PR: https://git.openjdk.java.net/jdk/pull/5372

Reply via email to