8350646: Calendar.Builder.build() Throws ArrayIndexOutOfBoundsException

Reviewed-by: naoto
This commit is contained in:
Justin Lu 2025-02-28 19:37:36 +00:00
parent 197004f4c6
commit 3a7d986878
4 changed files with 36 additions and 6 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1856,6 +1856,14 @@ class JapaneseImperialCalendar extends Calendar {
if (isSet(ERA)) {
era = internalGet(ERA);
// Don't check under, historically we have allowed values under
// BEFORE_MEIJI to be ignored during normalization
// We check against eras.length (not the highest constant ERA value)
// due to future added eras, or additional eras via
// "jdk.calendar.japanese.supplemental.era"
if (era >= eras.length) {
throw new IllegalArgumentException("Invalid era");
}
year = isSet(YEAR) ? internalGet(YEAR) : 1;
} else {
if (isSet(YEAR)) {