On Fri, 2 Sep 2022 11:38:27 GMT, ScientificWare <[email protected]> wrote:

>> src/java.desktop/share/classes/javax/swing/text/html/CSS.java line 1411:
>> 
>>> 1409:             Color color = colorNamed.get(strlc);
>>> 1410:             if (color != null) {
>>> 1411:                 return new Color(color.getRGB(), true);
>> 
>> Can you explain why you can't return the color instance directly ?
>> They are immutable so I don't see the reason.
>
> To avoid change method behaviour, I tried to reproduce previous behaviors 
> because returned objects can be publicly exposed trough 
> javax.swing.text.html.StyleSheet stringToColor method.
> Previous implementation :
> When, "" returns always the same object Color.Black.
> When,  "black", "silver", "white", ...,  rgb colors defined ... returns a new 
> object.
> I haven't a example list in mind but at least Color1 == Color2 is different 
> according implementation.

I think Phil is talking about just `return`ing the result, which doesn't change 
behavior. `""` can still `return Color.BLACK;` with the others creating a new 
object, ditching the oddly-placed temporary `Color` object.

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

PR: https://git.openjdk.org/jdk/pull/9825

Reply via email to