JDK-8187649 : ArrayIndexOutOfBoundsException in java.util.JapaneseImperialCalendar
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2017-09-15
  • Updated: 2025-01-29
  • Resolved: 2021-05-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 17 JDK 8 Other
11.0.14-oracleFixed 17 b25Fixed 8u321Fixed openjdk8u322Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
All versions since at least JDK6

ADDITIONAL OS VERSION INFORMATION :
All OSes

A DESCRIPTION OF THE PROBLEM :
There is an obvious ArrayIndexOutOfBoundsException in java.util.JapaneseImperialCalendar.actualMonthLength():
The third and fourth lines read

if (eraIndex == -1) {
	long transitionFixedDate = sinceFixedDates[eraIndex];

thereby always trying to access an out ouf bounds element on sinceFixedDates.


REPRODUCIBILITY :
This bug can be reproduced always.


Comments
Fix Request (8u) A clean backport for parity with Oracle 8u321. Affected test passed with patch.
04-10-2021

Fix Request (11u) A clean backport for parity with Oracle 11.0.14. Affected test passed with patch.
04-10-2021

Changeset: bea4109e Author: Naoto Sato <naoto@openjdk.org> Date: 2021-05-27 13:18:34 +0000 URL: https://git.openjdk.java.net/jdk/commit/bea4109ef75a6536af4296db56e6ec90ab0f30fc
27-05-2021

Now it is offending some static analysis tools: https://mail.openjdk.java.net/pipermail/core-libs-dev/2021-May/077986.html
24-05-2021

Obviously, the code should be: --- a/src/java.base/share/classes/java/util/JapaneseImperialCalendar.java +++ b/src/java.base/share/classes/java/util/JapaneseImperialCalendar.java @@ -2220,7 +2220,7 @@ private int actualMonthLength() { int length = jcal.getMonthLength(jdate); int eraIndex = getTransitionEraIndex(jdate); - if (eraIndex == -1) { + if (eraIndex != -1) { long transitionFixedDate = sinceFixedDates[eraIndex]; CalendarDate d = eras[eraIndex].getSinceDate(); if (transitionFixedDate <= cachedFixedDate) {
20-09-2017