8387261: Locale.LanguageRange should reject Double.NaN#31697
8387261: Locale.LanguageRange should reject Double.NaN#31697justin-curtis-lu wants to merge 2 commits into
Conversation
|
👋 Welcome back jlu! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
@justin-curtis-lu The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
| public LanguageRange(String range, double weight) { | ||
| Objects.requireNonNull(range); | ||
| if (weight < MIN_WEIGHT || weight > MAX_WEIGHT) { | ||
| if (weight < MIN_WEIGHT || weight > MAX_WEIGHT || Double.isNaN(weight)) { |
There was a problem hiding this comment.
Since the constructor now throws IllegalArgumentException for NaN weights, this should also be specified in the @throws tag, as NaN does not satisfy either NaN < MIN_WEIGHT or NaN > MAX_WEIGHT.
There was a problem hiding this comment.
How about updating the @throws wording to be
... or if the given {@code weight} is not between {@code MIN_WEIGHT} and {@code MAX_WEIGHT}, inclusive.
which would cover the NaN case without having to explicitly call it out.
There was a problem hiding this comment.
That wording is technically fine, but I would still prefer to call out NaN explicitly. NaN is unordered, so it is a different case from an ordinary out-of-range value, and it is the specific edge case being fixed here.
How about:
... or if the given {@code weight} is {@code NaN}, less than {@code MIN_WEIGHT}, or greater than {@code MAX_WEIGHT}.
|
Does any spec update need to be done to accommodate (It compares equal to |
I don't think a spec update is needed for |
|
Yes, for the constructor, I believe we are covered on the -0.0 case with the current throws wording. What is more questionable are the These methods are specified to throw if the weight is not a RFC 2616 qvalue,
However, since the implementation relies on We may need to soften the specification’s reliance on RFC 2616, perhaps by defining accepted weights in terms of the RFC 2616 minimum and maximum quality weight boundaries, rather than saying they exactly match RFC 2616 quality values. We could also take a different approach and clarify via an I am not sure if either of you would have a preference. |
I'd prefer the latter, since some implementation might want to strictly follow the RFC2616 spec. So we can say the JDK's implementation allows more than three fraction digits, or scientific notations as an btw, I wrote: Not RFC 2616, which is now obsolete, but the latest RFC 9110 reads: So the value of 0 is "not acceptable" in their terminology 🙂 |
This PR addresses an edge case where the
Locale.LanguageRange(String, double)constructor acceptsDouble.NaNas a weight. ALanguageRangeweight is specified by https://datatracker.ietf.org/doc/html/rfc2616#section-3.9 and must be between 0.0 and 1.0, inclusive. The existing bounds checks do not handle this case. This change adds an explicitDouble.isNaN(weight)check.The issue does not affect parsed range strings in the same way, since the input is normalized to lower case before parsing and
"nan"is not accepted byDouble.parseDouble. However, I added a test for that case as well, since one did not previously exist.Progress
Issues
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/31697/head:pull/31697$ git checkout pull/31697Update a local copy of the PR:
$ git checkout pull/31697$ git pull https://git.openjdk.org/jdk.git pull/31697/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 31697View PR using the GUI difftool:
$ git pr show -t 31697Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/31697.diff
Using Webrev
Link to Webrev Comment