提交 272dd1ae 编写于 作者: D dmeetry

8044671: NPE from JapaneseEra when a new era is defined in calendar.properties

Reviewed-by: okutsu
上级 05d96cf7
...@@ -127,7 +127,7 @@ public final class JapaneseEra ...@@ -127,7 +127,7 @@ public final class JapaneseEra
// the number of defined JapaneseEra constants. // the number of defined JapaneseEra constants.
// There could be an extra era defined in its configuration. // There could be an extra era defined in its configuration.
private static final int N_ERA_CONSTANTS = HEISEI.getValue() + ERA_OFFSET + 1; private static final int N_ERA_CONSTANTS = HEISEI.getValue() + ERA_OFFSET;
/** /**
* Serialization version. * Serialization version.
...@@ -148,7 +148,7 @@ public final class JapaneseEra ...@@ -148,7 +148,7 @@ public final class JapaneseEra
for (int i = N_ERA_CONSTANTS; i < ERA_CONFIG.length; i++) { for (int i = N_ERA_CONSTANTS; i < ERA_CONFIG.length; i++) {
CalendarDate date = ERA_CONFIG[i].getSinceDate(); CalendarDate date = ERA_CONFIG[i].getSinceDate();
LocalDate isoDate = LocalDate.of(date.getYear(), date.getMonth(), date.getDayOfMonth()); LocalDate isoDate = LocalDate.of(date.getYear(), date.getMonth(), date.getDayOfMonth());
KNOWN_ERAS[i] = new JapaneseEra(i - ERA_OFFSET, isoDate); KNOWN_ERAS[i] = new JapaneseEra(i - ERA_OFFSET + 1, isoDate);
} }
}; };
...@@ -195,7 +195,7 @@ public final class JapaneseEra ...@@ -195,7 +195,7 @@ public final class JapaneseEra
* @throws DateTimeException if the value is invalid * @throws DateTimeException if the value is invalid
*/ */
public static JapaneseEra of(int japaneseEra) { public static JapaneseEra of(int japaneseEra) {
if (japaneseEra < MEIJI.eraValue || japaneseEra + ERA_OFFSET - 1 >= KNOWN_ERAS.length) { if (japaneseEra < MEIJI.eraValue || japaneseEra + ERA_OFFSET > KNOWN_ERAS.length) {
throw new DateTimeException("Invalid era: " + japaneseEra); throw new DateTimeException("Invalid era: " + japaneseEra);
} }
return KNOWN_ERAS[ordinal(japaneseEra)]; return KNOWN_ERAS[ordinal(japaneseEra)];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册