Skip to content

Commit d39aad9

Browse files
committedSep 22, 2021
8273924: ArrayIndexOutOfBoundsException thrown in java.util.JapaneseImperialCalendar.add()
Reviewed-by: rriggs, iris, joehw
1 parent c9de806 commit d39aad9

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed
 

‎src/java.base/share/classes/sun/util/calendar/BaseCalendar.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 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
@@ -277,6 +277,10 @@ void normalizeMonth(CalendarDate date) {
277277
long xm = 1L - month;
278278
year -= (int)((xm / 12) + 1);
279279
month = 13 - (xm % 12);
280+
if (month == 13) {
281+
year++;
282+
month = 1;
283+
}
280284
bdate.setNormalizedYear(year);
281285
bdate.setMonth((int) month);
282286
} else if (month > DECEMBER) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/*
2525
* @test
2626
* @summary tests Japanese Calendar.
27-
* @bug 4609228 8187649
27+
* @bug 4609228 8187649 8273924
2828
* @modules java.base/sun.util
2929
* java.base/sun.util.calendar
3030
* @compile

‎test/jdk/java/util/Calendar/CalendarTestScripts/japanese/japanese_add.cts

+20
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,26 @@ test add MONTH
354354
# check date Heisei $max Aug 16
355355
# check timeofday 23 59 59 999
356356

357+
# JDK-8273924
358+
set date Reiwa 2 Mar 1
359+
add month -10
360+
check date Reiwa 1 May 1
361+
set date Reiwa 2 Mar 1
362+
add month -11
363+
check date Heisei 31 Apr 1
364+
set date Reiwa 2 Mar 1
365+
add month -12
366+
check date Heisei 31 Mar 1
367+
set date Reiwa 2 Mar 1
368+
add month -13
369+
check date Heisei 31 Feb 1
370+
set date Reiwa 2 Mar 1
371+
add month -14
372+
check date Heisei 31 Jan 1
373+
set date Reiwa 2 Mar 1
374+
add month -15
375+
check date Heisei 30 Dec 1
376+
357377
test add WEEK_OF_YEAR
358378
use jcal
359379
clear all

0 commit comments

Comments
 (0)
Please sign in to comment.