8349883: Locale.LanguageRange.parse("-") throws ArrayIndexOutOfBoundsException

Reviewed-by: naoto
This commit is contained in:
Justin Lu 2025-02-13 22:25:23 +00:00
parent 3e7acfac48
commit 3741c980b8
3 changed files with 71 additions and 77 deletions

View file

@ -3266,9 +3266,7 @@ public final class Locale implements Cloneable, Serializable {
* or greater than {@code MAX_WEIGHT}
*/
public LanguageRange(String range, double weight) {
if (range == null) {
throw new NullPointerException();
}
Objects.requireNonNull(range);
if (weight < MIN_WEIGHT || weight > MAX_WEIGHT) {
throw new IllegalArgumentException("weight=" + weight);
}
@ -3278,8 +3276,8 @@ public final class Locale implements Cloneable, Serializable {
// Do syntax check.
boolean isIllFormed = false;
String[] subtags = range.split("-");
if (isSubtagIllFormed(subtags[0], true)
|| range.endsWith("-")) {
if (range.endsWith("-") ||
isSubtagIllFormed(subtags[0], true)) {
isIllFormed = true;
} else {
for (int i = 1; i < subtags.length; i++) {