Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/DateFormat/Bug8193444.java
41152 views
1
/*
2
* Copyright (c) 2018, Oracle 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
* @test
25
* @bug 8193444
26
* @summary Checks SimpleDateFormat.format/parse for the AIOOB exception when
27
* formatting/parsing dates through a pattern string that contains a
28
* sequence of 256 or more non-ASCII unicode characters.
29
* @run testng/othervm Bug8193444
30
*/
31
import org.testng.annotations.DataProvider;
32
import org.testng.annotations.Test;
33
34
import java.text.DateFormat;
35
import java.text.ParseException;
36
import java.text.SimpleDateFormat;
37
import java.util.Date;
38
39
import static org.testng.Assert.assertEquals;
40
41
public class Bug8193444 {
42
43
private static final String NON_ASCII_CHAR = "\u263A";
44
45
@DataProvider(name = "dateFormat")
46
Object[][] dateFormatData() {
47
return new Object[][]{
48
// short_length (between 0 and 254)
49
{250},
50
// boundary
51
{254},
52
// long_length
53
{257},};
54
}
55
56
@Test(dataProvider = "dateFormat")
57
public void testDateFormatAndParse(int length)
58
throws ParseException {
59
60
String pattern = NON_ASCII_CHAR.repeat(length);
61
62
DateFormat df = new SimpleDateFormat(pattern);
63
// format() should not throw AIOOB exception
64
String result = df.format(new Date());
65
66
// Since the tested format patterns do not contain any character
67
// representing date/time field, those characters are not interpreted,
68
// they are simply copied into the output string during formatting
69
assertEquals(result, pattern, "Failed to format the date using"
70
+ " pattern of length: " + length);
71
72
// The format pattern used by this SimpleDateFormat
73
// contains a sequence of non-ASCII characters, which does not
74
// represent any date/time field. The same sequence is given
75
// for parsing, just to check that the parsing does
76
// not throw any AIOOB exception.
77
// Although as per the parse() specification, the calendar's default
78
// values of the date-time fields are used for any missing
79
// date-time information, but checking that is not the intention of
80
// this test.
81
df.parse(pattern);
82
}
83
84
}
85
86