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

ArrayIndexOutOfBoundsException thrown in java.util.JapaneseImperialCalendar.add()

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b16
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        java.util.Calendar.add throws ArrayIndexOutOfBoundsException under the below condition.

        X = 1- ((Calendar.MONTH+1) + amount), and if X is a multiple of 12, AIOOBE is thrown.

        The reproducer is below:

        jshell> var calendar = Calendar.getInstance(new Locale("ja", "JP", "JP"))
        calendar ==> java.util.JapaneseImperialCalendar[time=163184924 ...
        SET=32400000,DST_OFFSET=0]

        jshell> var month = 2
        month ==> 2

        jshell> var amount = -14
        amount ==> -14

        jshell> calendar.set(2, month, 1, 1, 0)

        jshell> calendar.add(Calendar.MONTH, amount)
        | 例外java.lang.ArrayIndexOutOfBoundsException: Index 13 out of bounds for
        length 13
        | at BaseCalendar.getDayOfYear (BaseCalendar.java:348)
        | at BaseCalendar.getFixedDate (BaseCalendar.java:381)
        | at BaseCalendar.getFixedDate (BaseCalendar.java:356)
        | at AbstractCalendar.getTime (AbstractCalendar.java:175)
        | at BaseCalendar.normalize (BaseCalendar.java:228)
        | at LocalGregorianCalendar.normalize
        (LocalGregorianCalendar.java:328)
        | at JapaneseImperialCalendar.pinDayOfMonth
        (JapaneseImperialCalendar.java:2288)
        | at JapaneseImperialCalendar.add (JapaneseImperialCalendar.java:452)
        | at (#5:1)


        In this reproducer, X=1-((2+1)+(-14)) = 12. In this case, AIOOBE is thrown.
        The issue is reproduced in 18, 16.0.2, 11.0.13 and 8u311.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                naoto Naoto Sato
                Reporter:
                shadowbug Shadow Bug
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: