8044671: NPE from JapaneseEra when a new era is defined in calendar.properties
authordmeetry
Fri, 01 Aug 2014 16:29:46 +0400
changeset 25802 1dc2d3b5d4e6
parent 25801 da76619a8c19
child 25803 ab8f8e106d0a
8044671: NPE from JapaneseEra when a new era is defined in calendar.properties Reviewed-by: okutsu
jdk/src/share/classes/java/time/chrono/JapaneseEra.java
--- a/jdk/src/share/classes/java/time/chrono/JapaneseEra.java	Fri Aug 01 12:05:05 2014 +0000
+++ b/jdk/src/share/classes/java/time/chrono/JapaneseEra.java	Fri Aug 01 16:29:46 2014 +0400
@@ -127,7 +127,7 @@
 
     // the number of defined JapaneseEra constants.
     // 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.
@@ -148,7 +148,7 @@
         for (int i = N_ERA_CONSTANTS; i < ERA_CONFIG.length; i++) {
             CalendarDate date = ERA_CONFIG[i].getSinceDate();
             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 @@
      * @throws DateTimeException if the value is invalid
      */
     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);
         }
         return KNOWN_ERAS[ordinal(japaneseEra)];