Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/String/concat/StringConcatFactoryRepeatedConstants.java
41153 views
1
/*
2
* Copyright (c) 2019, 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
import java.lang.invoke.CallSite;
25
import java.lang.invoke.MethodHandles;
26
import java.lang.invoke.MethodType;
27
import java.lang.invoke.StringConcatFactory;
28
29
/**
30
* @test
31
* @summary StringConcatFactory allow recipes with repeated constants, but this
32
* is not expressible with java code and needs an explicit sanity test
33
* @bug 8222852
34
*
35
* @compile StringConcatFactoryRepeatedConstants.java
36
*
37
* @run main/othervm -Xverify:all StringConcatFactoryRepeatedConstants
38
*/
39
public class StringConcatFactoryRepeatedConstants {
40
41
public static void main(String[] args) throws Throwable {
42
43
CallSite site = StringConcatFactory.makeConcatWithConstants(
44
MethodHandles.lookup(),
45
"foo",
46
MethodType.methodType(String.class),
47
"\u0002\u0002",
48
"foo", "bar"
49
);
50
String string = (String)site.dynamicInvoker().invoke();
51
if (!"foobar".equals(string)) {
52
throw new IllegalStateException("Expected: foobar, got: " + string);
53
}
54
55
site = StringConcatFactory.makeConcatWithConstants(
56
MethodHandles.lookup(),
57
"foo",
58
MethodType.methodType(String.class),
59
"\u0002\u0002test\u0002\u0002",
60
"foo", 17.0f, 4711L, "bar"
61
);
62
string = (String)site.dynamicInvoker().invoke();
63
StringBuilder sb = new StringBuilder();
64
sb.append("foo").append(17.0f).append("test").append(4711L).append("bar");
65
if (!sb.toString().equals(string)) {
66
throw new IllegalStateException("Expected: " + sb.toString() + ", got: " + string);
67
}
68
}
69
70
}
71
72