Skip to content

Commit

Permalink
8187649: ArrayIndexOutOfBoundsException in java.util.JapaneseImperial…
Browse files Browse the repository at this point in the history
…Calendar

Backport-of: bea4109
  • Loading branch information
zhengyu123 committed Oct 4, 2021
1 parent 6285123 commit 3b88f74
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -885,7 +885,7 @@ public void roll(int field, int amount) {
} else if (nfd >= (month1 + monthLength)) {
nfd = month1 + monthLength - 1;
}
set(DAY_OF_MONTH, (int)(nfd - month1) + 1);
set(DAY_OF_MONTH, getCalendarDate(nfd).getDayOfMonth());
return;
}

Expand Down Expand Up @@ -1457,7 +1457,7 @@ public int getActualMaximum(int field) {
CalendarDate d = gcal.newCalendarDate(TimeZone.NO_TIMEZONE);
d.setDate(date.getNormalizedYear(), date.getMonth(), 1);
int dayOfWeek = gcal.getDayOfWeek(d);
int monthLength = gcal.getMonthLength(d);
int monthLength = actualMonthLength();
dayOfWeek -= getFirstDayOfWeek();
if (dayOfWeek < 0) {
dayOfWeek += 7;
Expand Down Expand Up @@ -2238,7 +2238,7 @@ private int monthLength(int month) {
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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,7 +24,7 @@
/*
* @test
* @summary tests Japanese Calendar.
* @bug 4609228
* @bug 4609228 8187649
* @modules java.base/sun.util
* java.base/sun.util.calendar
* @compile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,48 @@ test roll WEEK_OF_YEAR
check date BeforeMeiji $minyear Dec 25

test WEEK_OF_MONTH
# Needs to wait for 6191841 fix. (WEEK_OF_MONTH needs to change
# ERA and YEAR in a transition month.)
use jcal
clear all

# Make sure this test does not throw AIOOBE
set date Heisei 1 Aug 1
roll week_of_month 1
check date Heisei 1 Aug 8

# Check transition dates
set date Showa 64 Jan 7
roll week_of_month 1
check date Showa 64 Jan 7
roll week_of_month -1
check date Showa 64 Jan 7

set date Heisei 1 Jan 31
roll week_of_month 1
check date Heisei 1 Jan 10
roll week_of_month -1
check date Heisei 1 Jan 31

test DAY_OF_MONTH
# Needs to wait for 6191841 fix. (DAY_OF_MONTH needs to change
# ERA and YEAR in a transition month.)
use jcal
clear all

# Make sure this test does not throw AIOOBE
Set date Heisei 1 Aug 1
roll day_of_month 1
check date Heisei 1 Aug 2

# Check transition dates
set date Showa 64 Jan 7
roll day_of_month 1
check date Showa 64 Jan 1
roll day_of_month -1
check date Showa 64 Jan 7

set date Heisei 1 Jan 31
roll day_of_month 1
check date Heisei 1 Jan 8
roll day_of_month -1
check date Heisei 1 Jan 31

test DAY_OF_YEAR
use jcal
Expand Down

1 comment on commit 3b88f74

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.