Skip to content

Commit 3b88f74

Browse files
committed
8187649: ArrayIndexOutOfBoundsException in java.util.JapaneseImperialCalendar
Backport-of: bea4109
1 parent 6285123 commit 3b88f74

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

src/java.base/share/classes/java/util/JapaneseImperialCalendar.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -885,7 +885,7 @@ public void roll(int field, int amount) {
885885
} else if (nfd >= (month1 + monthLength)) {
886886
nfd = month1 + monthLength - 1;
887887
}
888-
set(DAY_OF_MONTH, (int)(nfd - month1) + 1);
888+
set(DAY_OF_MONTH, getCalendarDate(nfd).getDayOfMonth());
889889
return;
890890
}
891891

@@ -1457,7 +1457,7 @@ public int getActualMaximum(int field) {
14571457
CalendarDate d = gcal.newCalendarDate(TimeZone.NO_TIMEZONE);
14581458
d.setDate(date.getNormalizedYear(), date.getMonth(), 1);
14591459
int dayOfWeek = gcal.getDayOfWeek(d);
1460-
int monthLength = gcal.getMonthLength(d);
1460+
int monthLength = actualMonthLength();
14611461
dayOfWeek -= getFirstDayOfWeek();
14621462
if (dayOfWeek < 0) {
14631463
dayOfWeek += 7;
@@ -2238,7 +2238,7 @@ private int monthLength(int month) {
22382238
private int actualMonthLength() {
22392239
int length = jcal.getMonthLength(jdate);
22402240
int eraIndex = getTransitionEraIndex(jdate);
2241-
if (eraIndex == -1) {
2241+
if (eraIndex != -1) {
22422242
long transitionFixedDate = sinceFixedDates[eraIndex];
22432243
CalendarDate d = eras[eraIndex].getSinceDate();
22442244
if (transitionFixedDate <= cachedFixedDate) {

test/jdk/java/util/Calendar/CalendarTestScripts/JapaneseTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
2424
/*
2525
* @test
2626
* @summary tests Japanese Calendar.
27-
* @bug 4609228
27+
* @bug 4609228 8187649
2828
* @modules java.base/sun.util
2929
* java.base/sun.util.calendar
3030
* @compile

test/jdk/java/util/Calendar/CalendarTestScripts/japanese/japanese_roll.cts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,48 @@ test roll WEEK_OF_YEAR
435435
check date BeforeMeiji $minyear Dec 25
436436

437437
test WEEK_OF_MONTH
438-
# Needs to wait for 6191841 fix. (WEEK_OF_MONTH needs to change
439-
# ERA and YEAR in a transition month.)
438+
use jcal
439+
clear all
440+
441+
# Make sure this test does not throw AIOOBE
442+
set date Heisei 1 Aug 1
443+
roll week_of_month 1
444+
check date Heisei 1 Aug 8
445+
446+
# Check transition dates
447+
set date Showa 64 Jan 7
448+
roll week_of_month 1
449+
check date Showa 64 Jan 7
450+
roll week_of_month -1
451+
check date Showa 64 Jan 7
452+
453+
set date Heisei 1 Jan 31
454+
roll week_of_month 1
455+
check date Heisei 1 Jan 10
456+
roll week_of_month -1
457+
check date Heisei 1 Jan 31
440458

441459
test DAY_OF_MONTH
442-
# Needs to wait for 6191841 fix. (DAY_OF_MONTH needs to change
443-
# ERA and YEAR in a transition month.)
460+
use jcal
461+
clear all
462+
463+
# Make sure this test does not throw AIOOBE
464+
Set date Heisei 1 Aug 1
465+
roll day_of_month 1
466+
check date Heisei 1 Aug 2
467+
468+
# Check transition dates
469+
set date Showa 64 Jan 7
470+
roll day_of_month 1
471+
check date Showa 64 Jan 1
472+
roll day_of_month -1
473+
check date Showa 64 Jan 7
474+
475+
set date Heisei 1 Jan 31
476+
roll day_of_month 1
477+
check date Heisei 1 Jan 8
478+
roll day_of_month -1
479+
check date Heisei 1 Jan 31
444480

445481
test DAY_OF_YEAR
446482
use jcal

0 commit comments

Comments
 (0)