RFR: 8301302: Platform preferences API [v18]

John Hendrikx jhendrikx at openjdk.org
Wed Nov 1 08:27:41 UTC 2023


On Wed, 1 Nov 2023 02:16:23 GMT, Michael Strauß <mstrauss at openjdk.org> wrote:

>> modules/javafx.graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java line 1094:
>> 
>>> 1092:     // This method will be removed when StyleThemes are added.
>>> 1093:     private static void checkHighContrastThemeChanged(Map<String, Object> preferences) {
>>> 1094:         if (preferences.get("Windows.SPI.HighContrastOn") == Boolean.TRUE) {
>> 
>> It's better to not use reference equality here, as `new Boolean("true") != Boolean.TRUE`.
>> Suggestion:
>> 
>>         if (Boolean.TRUE.equals(preferences.get("Windows.SPI.HighContrastOn")) {
>
> This might not be an issue, considering that the Boolean(String) constructor is terminally deprecated anyway.

It might not be, or it may become a bigger issue than it is now.  Why take the risk?  The rule in Java is always the same, objects are compared with `equals` unless you specifically need reference equality.

You don't do this with other primitive wrappers either (because you are probably aware of things like the integer cache, which is just an implementation detail and no guarantee).  Same for these booleans, you're relying on implementation details for this to work correctly.

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

PR Review Comment: https://git.openjdk.org/jfx/pull/1014#discussion_r1378512740


More information about the openjfx-dev mailing list