RFR: 8377427: Reduce substring allocations in Color.web(String, double) [v2]
Michael Strauß
mstrauss at openjdk.org
Wed Feb 11 09:57:04 UTC 2026
On Tue, 10 Feb 2026 16:49:56 GMT, Andy Goryachev <angorya at openjdk.org> wrote:
> The JavaFX CSS spec states (under <number>):
>
> ```
> Real numbers and integers are specified in decimal notation only. ... A <number> can either be an <integer>, or it can be zero or more digits followed by a dot (.) followed by one or more digits. Both integers and real numbers may be preceded by a "-" or "+" to indicate the sign. -0 is equivalent to 0 and is not a negative number.
>
> [+|-]? [[0-9]+|[0-9]*"."[0-9]+]
> ```
>
> it looks to me like exponential notation should not be supported.
>
In the interest of not being different just for the sake of it, we should probably change this specification and use the W3C definition of a number everywhere. Not terribly important (no one uses E notation anyway), but better be consistent.
> Mandatory disclaimer: W3C is not a real standard.
[5.8 billion](https://sqmagazine.co.uk/web-browser-usage-statistics/#Web-Browser-Market-Size-Growth-2018%E2%80%932025) web browser installations disagree. What fraction of a fraction of a percent of this number is JavaFX again? W3C's baseline compatibility standard is as good as any standard can possibly be. There are no other CSS specifications of any significance whatsoever.
> I am not sure if we want to change the CSS spec to allow scientific notation in all the s, I don't even sure we want to add this support in `Color.web()`. If we do though, I think we would need to update the javadoc and possibly the CSS Reference, right?
Right now, the situation is a bit inconsistent:
* Doesn't parse: `rgb(1E2, 0, 0)`
* Parses: `rgb(1E2%, 0, 0)`
* Doesn't parse: `rgb(1E2%, 100.0, 100)`
* Parses: `rgb(1E2%, 100, 100)`
JavaFX contradicts its own specification, but the specification is (and has always been) wrong anyway.
> modules/javafx.graphics/src/main/java/javafx/scene/paint/Color.java line 405:
>
>> 403: if (colorString.regionMatches(true, 0, "#", 0, 1)) {
>> 404: offset = 1;
>> 405: } else if (colorString.regionMatches(true, 0, "0x", 0, 2)) {
>
> interestingly, while the code (both old and new) ignores case, the javadoc says nothing about case sensitivity.
It does say that it parses a CSS color string, and CSS is case-insensitive.
> modules/javafx.graphics/src/test/java/test/com/sun/javafx/css/parser/CssNumberParserTest.java line 40:
>
>> 38: @Test
>> 39: public void parseIntegerAndSignedInteger() {
>> 40: assertEquals(0.0, parseDouble("0"), 0.0);
>
> The JavaFX CSS spec also states
>
>
> -0 is equivalent to 0 and is not a negative number.
>
>
> How should we test this?
On the JVM, `-0 == 0`. It seems to me that this sentence just spells it out, doesn't it?
-------------
PR Comment: https://git.openjdk.org/jfx/pull/2069#issuecomment-3879937950
PR Comment: https://git.openjdk.org/jfx/pull/2069#issuecomment-3880451384
PR Review Comment: https://git.openjdk.org/jfx/pull/2069#discussion_r2788966646
PR Review Comment: https://git.openjdk.org/jfx/pull/2069#discussion_r2789556392
More information about the openjfx-dev
mailing list