Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/invoke/MethodHandlesArityLimitsTest.java
41149 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
* @summary unit tests for arity limits of methods in java.lang.invoke.MethodHandles
26
* @run junit/othervm test.java.lang.invoke.MethodHandlesArityLimitsTest
27
**/
28
29
package test.java.lang.invoke;
30
31
import org.junit.*;
32
33
import java.lang.invoke.MethodHandles;
34
import java.lang.invoke.MethodHandle;
35
import java.lang.invoke.WrongMethodTypeException;
36
import java.lang.invoke.MethodType;
37
import java.lang.invoke.VarHandle;
38
import java.util.List;
39
40
import java.util.stream.IntStream;
41
42
import static org.junit.Assert.*;
43
44
public class MethodHandlesArityLimitsTest {
45
46
private static MethodType mt254 = null;
47
private static MethodType mt255 = null;
48
49
static {
50
Class<?>[] classes254 = IntStream.range(0, 254)
51
.mapToObj(i -> int.class)
52
.toArray(Class[]::new);
53
mt254 = MethodType.methodType(void.class, classes254);
54
mt255 = mt254.appendParameterTypes(int.class);
55
}
56
57
@Test(expected = IllegalArgumentException.class)
58
public void testDropArgumentsToMatch() {
59
MethodHandles.dropArgumentsToMatch(MethodHandles.empty(mt254), 0, mt255.parameterList(), 0);
60
}
61
62
@Test(expected = IllegalArgumentException.class)
63
public void testEmpty() {
64
MethodHandles.empty(mt255);
65
}
66
67
@Test(expected = IllegalArgumentException.class)
68
public void testExplicitCastArguments() {
69
MethodHandles.explicitCastArguments(
70
MethodHandles.empty(mt254),
71
mt254.dropParameterTypes(0, 1).insertParameterTypes(0, long.class) );
72
}
73
74
@Test(expected = IllegalArgumentException.class)
75
public void testPermuteArguments() {
76
MethodHandles.permuteArguments(
77
MethodHandles.empty(MethodType.methodType(void.class)),
78
mt255);
79
}
80
81
@Test(expected = IllegalArgumentException.class)
82
public void testVarHandleInvoker() {
83
MethodHandles.varHandleInvoker(VarHandle.AccessMode.GET, mt254);
84
}
85
86
@Test(expected = IllegalArgumentException.class)
87
public void testVarHandleExactInvoker() {
88
MethodHandles.varHandleExactInvoker(VarHandle.AccessMode.GET, mt254);
89
}
90
91
@Test(expected = IllegalArgumentException.class)
92
public void testMHExactInvoker() {
93
MethodHandles.exactInvoker(mt255);
94
}
95
96
@Test(expected = IllegalArgumentException.class)
97
public void testMHInvoker() {
98
MethodHandles.invoker(mt255);
99
}
100
101
@Test(expected = IllegalArgumentException.class)
102
public void testMHSpreadInvoker() {
103
MethodHandles.spreadInvoker(mt255, 255);
104
}
105
106
@Test(expected = WrongMethodTypeException.class)
107
public void testAsType() throws ReflectiveOperationException {
108
MethodHandle asList = MethodHandles.lookup().findStatic(
109
java.util.Arrays.class,
110
"asList",
111
MethodType.methodType(List.class, Object[].class));
112
try {
113
asList.asType(MethodType.genericMethodType(254));//does not throw IAE or WMTE
114
}
115
catch(WrongMethodTypeException wmte) {
116
throw new AssertionError("Unexpected WrongMethodTypeException thrown", wmte);
117
}
118
asList.asType(MethodType.genericMethodType(255));//throws WMTE
119
}
120
}
121
122