changeset 9882:efd23426486a

8044671: NPE from JapaneseEra when a new era is defined in calendar.properties Reviewed-by: okutsu
author dmeetry
date Fri, 01 Aug 2014 16:29:46 +0400
parents 1bd6e464e8df
children 82d322b02950
files src/share/classes/java/time/chrono/JapaneseEra.java
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/time/chrono/JapaneseEra.java	Sat Jul 26 03:18:05 2014 +0400
+++ b/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)];