author | nishjain |
Fri, 13 Jul 2018 14:04:59 +0530 | |
changeset 51054 | 147b20e60274 |
permissions | -rw-r--r-- |
51054
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
1 |
/* |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
4 |
* |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
8 |
* |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
13 |
* accompanied this code). |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
14 |
* |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
18 |
* |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
21 |
* questions. |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
22 |
*/ |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
23 |
/* |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
24 |
* @test |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
25 |
* @bug 8193444 |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
26 |
* @summary Checks SimpleDateFormat.format/parse for the AIOOB exception when |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
27 |
* formatting/parsing dates through a pattern string that contains a |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
28 |
* sequence of 256 or more non-ASCII unicode characters. |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
29 |
* @run testng/othervm Bug8193444 |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
30 |
*/ |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
31 |
import org.testng.annotations.DataProvider; |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
32 |
import org.testng.annotations.Test; |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
33 |
|
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
34 |
import java.text.DateFormat; |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
35 |
import java.text.ParseException; |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
36 |
import java.text.SimpleDateFormat; |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
37 |
import java.util.Date; |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
38 |
|
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
39 |
import static org.testng.Assert.assertEquals; |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
40 |
|
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
41 |
public class Bug8193444 { |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
42 |
|
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
43 |
private static final String NON_ASCII_CHAR = "\u263A"; |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
44 |
|
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
45 |
@DataProvider(name = "dateFormat") |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
46 |
Object[][] dateFormatData() { |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
47 |
return new Object[][]{ |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
48 |
// short_length (between 0 and 254) |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
49 |
{250}, |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
50 |
// boundary |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
51 |
{254}, |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
52 |
// long_length |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
53 |
{257},}; |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
54 |
} |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
55 |
|
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
56 |
@Test(dataProvider = "dateFormat") |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
57 |
public void testDateFormatAndParse(int length) |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
58 |
throws ParseException { |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
59 |
|
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
60 |
String pattern = NON_ASCII_CHAR.repeat(length); |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
61 |
|
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
62 |
DateFormat df = new SimpleDateFormat(pattern); |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
63 |
// format() should not throw AIOOB exception |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
64 |
String result = df.format(new Date()); |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
65 |
|
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
66 |
// Since the tested format patterns do not contain any character |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
67 |
// representing date/time field, those characters are not interpreted, |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
68 |
// they are simply copied into the output string during formatting |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
69 |
assertEquals(result, pattern, "Failed to format the date using" |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
70 |
+ " pattern of length: " + length); |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
71 |
|
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
72 |
// The format pattern used by this SimpleDateFormat |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
73 |
// contains a sequence of non-ASCII characters, which does not |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
74 |
// represent any date/time field. The same sequence is given |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
75 |
// for parsing, just to check that the parsing does |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
76 |
// not throw any AIOOB exception. |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
77 |
// Although as per the parse() specification, the calendar's default |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
78 |
// values of the date-time fields are used for any missing |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
79 |
// date-time information, but checking that is not the intention of |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
80 |
// this test. |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
81 |
df.parse(pattern); |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
82 |
} |
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
83 |
|
147b20e60274
8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents:
diff
changeset
|
84 |
} |