`CssParser.colorValueOfString()` parses a string into a `Color`. If this fails 
by throwing an exception, `null` is returned from `colorValueOfString()`, 
signalling to the caller that the color string might be a lookup instead.

Since color lookups can appear in many places in a CSS file, it is preferable 
to use return values for flow control instead of exceptions. For this purpose, 
we need non-throwing versions of methods that parse numbers and colors.

These are the changes in this PR:
1. Move color parsing from the `Color` class to `CssColorParser`. This is done 
so that we can access the new `tryParseColor(String)` method from `CssParser`, 
and also to separate concerns between color representation and parsing.
2. Add a non-throwing `CssNumberParser.tryParseDouble()`, which returns `NaN` 
to indicate a parsing failure. We can use `NaN` because it is not a valid 
return value of the parser.
3. Since color parsing also uses `Integer.parseInt()`, we need a non-throwing 
version of this method: `CssNumberParser.tryParseInt()`. Since we can't use any 
particular `int` as a return value that indicates failure, I've decided to 
return a `long` value instead, where a value less than `Integer.MIN_VALUE` 
indicates a parsing failure.

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

Commit messages:
 - exception-free parsing

Changes: https://git.openjdk.org/jfx/pull/2093/files
  Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=2093&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8378970
  Stats: 1477 lines in 5 files changed: 664 ins; 509 del; 304 mod
  Patch: https://git.openjdk.org/jfx/pull/2093.diff
  Fetch: git fetch https://git.openjdk.org/jfx.git pull/2093/head:pull/2093

PR: https://git.openjdk.org/jfx/pull/2093

Reply via email to