Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8350646

Calendar.Builder.build() Throws ArrayIndexOutOfBoundsException

XMLWordPrintable

    • 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 ----------

            jlu Justin Lu
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: