Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/StringBuffer/HugeCapacity.java
41149 views
1
/*
2
* Copyright (c) 2019, 2020, 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
/**
25
* @test
26
* @bug 8218227
27
* @summary StringBuilder/StringBuffer constructor throws confusing
28
* NegativeArraySizeException
29
* @requires (sun.arch.data.model == "64" & os.maxMemory >= 6G)
30
* @run main/othervm -Xms5G -Xmx5G HugeCapacity
31
*/
32
33
public class HugeCapacity {
34
private static int failures = 0;
35
36
public static void main(String[] args) {
37
testHugeInitialString();
38
testHugeInitialCharSequence();
39
if (failures > 0) {
40
throw new RuntimeException(failures + " tests failed");
41
}
42
}
43
44
private static void testHugeInitialString() {
45
try {
46
String str = "Z".repeat(Integer.MAX_VALUE - 8);
47
StringBuffer sb = new StringBuffer(str);
48
} catch (OutOfMemoryError ignore) {
49
} catch (Throwable unexpected) {
50
unexpected.printStackTrace();
51
failures++;
52
}
53
}
54
55
private static void testHugeInitialCharSequence() {
56
try {
57
CharSequence seq = new MyHugeCharSeq();
58
StringBuffer sb = new StringBuffer(seq);
59
} catch (OutOfMemoryError ignore) {
60
} catch (Throwable unexpected) {
61
unexpected.printStackTrace();
62
failures++;
63
}
64
}
65
66
private static class MyHugeCharSeq implements CharSequence {
67
public char charAt(int i) {
68
throw new UnsupportedOperationException();
69
}
70
public int length() { return Integer.MAX_VALUE; }
71
public CharSequence subSequence(int st, int e) {
72
throw new UnsupportedOperationException();
73
}
74
public String toString() { return ""; }
75
}
76
}
77
78