Skip to content

Commit

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

Reviewed-by: joehw, rriggs
  • Loading branch information
naotoj committed May 27, 2021
1 parent ec65cf8 commit bea4109
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
@@ -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 @@ -886,7 +886,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 @@ -1458,7 +1458,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 @@ -2239,7 +2239,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
@@ -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
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

0 comments on commit bea4109

Please sign in to comment.