On Fri, 26 Jun 2026 18:35:26 GMT, Naoto Sato <[email protected]> wrote:
>> This PR addresses an edge case where the `Locale.LanguageRange(String, >> double)` constructor accepts `Double.NaN` as a weight. A `LanguageRange` >> weight 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 explicit `Double.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 >> by `Double.parseDouble`. However, I added a test for that case as well, >> since one did not previously exist. >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > src/java.base/share/classes/java/util/Locale.java line 3217: > >> 3215: public LanguageRange(String range, double weight) { >> 3216: Objects.requireNonNull(range); >> 3217: if (weight < MIN_WEIGHT || weight > MAX_WEIGHT || >> Double.isNaN(weight)) { > > 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`. 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. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/31697#discussion_r3483488205
