- 
    Bug 
- 
    Resolution: Fixed
- 
     P4 P4
- 
    8, 11, 17, 21, 24
- 
        b13
- 
        generic
- 
        generic
                    A DESCRIPTION OF THE PROBLEM :
In Java's Calendar.Builder API, when setting an invalid ERA (e.g., ERA = 6) for a Japanese calendar (setCalendarType("japanese")), the build() method throws ArrayIndexOutOfBoundsException instead of the expected IllegalArgumentException.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
throw IllegalArgumentException.
ACTUAL -
throw ArrayIndexOutOfBoundsException
---------- BEGIN SOURCE ----------
import java.util.Calendar;
class Main {
public static void main(String[] args) {
try {
new Calendar.Builder()
.setCalendarType("japanese")
.setFields(Calendar.ERA, 6, Calendar.YEAR, 1, Calendar.MONTH, Calendar.MAY, Calendar.DAY_OF_MONTH, 1)
.build();
System.out.println("Test failed: Expected IllegalArgumentException but none was thrown.");
} catch (IllegalArgumentException e) {
System.out.println("Test passed: Caught expected IllegalArgumentException.");
} catch (Exception e) {
System.err.println("Test failed: Unexpected exception - " + e);
}
}
}
---------- END SOURCE ----------
            
In Java's Calendar.Builder API, when setting an invalid ERA (e.g., ERA = 6) for a Japanese calendar (setCalendarType("japanese")), the build() method throws ArrayIndexOutOfBoundsException instead of the expected IllegalArgumentException.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
throw IllegalArgumentException.
ACTUAL -
throw ArrayIndexOutOfBoundsException
---------- BEGIN SOURCE ----------
import java.util.Calendar;
class Main {
public static void main(String[] args) {
try {
new Calendar.Builder()
.setCalendarType("japanese")
.setFields(Calendar.ERA, 6, Calendar.YEAR, 1, Calendar.MONTH, Calendar.MAY, Calendar.DAY_OF_MONTH, 1)
.build();
System.out.println("Test failed: Expected IllegalArgumentException but none was thrown.");
} catch (IllegalArgumentException e) {
System.out.println("Test passed: Caught expected IllegalArgumentException.");
} catch (Exception e) {
System.err.println("Test failed: Unexpected exception - " + e);
}
}
}
---------- END SOURCE ----------
- csr for
- 
                    JDK-8350806 Calendar.Builder.build() Throws ArrayIndexOutOfBoundsException -           
- Closed
 
-         
- links to
- 
                     Commit(master)
        openjdk/jdk/3a7d9868 Commit(master)
        openjdk/jdk/3a7d9868
- 
                     Review(master)
        openjdk/jdk/23789 Review(master)
        openjdk/jdk/23789