Skip to content

Commit e7e182a

Browse files
cliveverghesesimonis
authored andcommitted
8235699: ArrayIndexOutOfBoundsException in CalendarBuilder.toString
Reviewed-by: phh, alanb, weijun, simonis, rriggs
1 parent ccb4ab5 commit e7e182a

File tree

3 files changed

+79
-3
lines changed

3 files changed

+79
-3
lines changed

src/java.base/share/classes/java/text/CalendarBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2020, 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
@@ -148,9 +148,9 @@ Calendar establish(Calendar cal) {
148148

149149
public String toString() {
150150
StringJoiner sj = new StringJoiner(",", "CalendarBuilder:[", "]");
151-
for (int i = 0; i < field.length; i++) {
151+
for (int i = 0; i < MAX_FIELD; i++) {
152152
if (isSet(i)) {
153-
sj.add(i + "=" + field[MAX_FIELD + i]);
153+
sj.add(i + "=" + field[i] + ":" + field[MAX_FIELD + i]);
154154
}
155155
}
156156
return sj.toString();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2020, Amazon and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8235699
27+
* @summary Check that CalendarBuilder.toString() does not throw an ArrayIndexOutOfBoundException
28+
* @build java.base/java.text.CalendarBuilderTest
29+
* @run main Bug8235699
30+
*/
31+
32+
33+
public class Bug8235699 {
34+
public static void main(String[] args) {
35+
java.text.CalendarBuilderTest.testCalendarBuilderToString();
36+
}
37+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2020, Amazon and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package java.text;
25+
26+
/**
27+
* Test validated that CalendarBuilder.toString does not throw an ArrayIndexOutOfBoundException.
28+
*/
29+
30+
import java.util.Calendar;
31+
32+
public class CalendarBuilderTest {
33+
public static void testCalendarBuilderToString() {
34+
CalendarBuilder calendarBuilder = new CalendarBuilder();
35+
calendarBuilder.set(Calendar.YEAR, 2020);
36+
calendarBuilder.toString();
37+
38+
}
39+
}

0 commit comments

Comments
 (0)