Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/invoke/8022701/InvokeSeveralWays.java
41153 views
1
/*
2
* Copyright (c) 2013, 2016, 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.reflect.InvocationTargetException;
25
26
/**
27
* Tries various ways of ultimately invoking MethodSupplier.m(),
28
* except that m has been made inaccessible and some exception should be
29
* thrown instead.
30
*/
31
public class InvokeSeveralWays {
32
public static int test(String args[], Class expected) throws Exception {
33
int failures = 0;
34
try {
35
Class.forName("Invoker").getMethod("invoke").invoke(null);
36
System.out.println("FAIL: No exception throw, probably failed to load modified bytecodes for MethodSupplier");
37
failures++;
38
} catch (InvocationTargetException e) {
39
Throwable c = e.getCause();
40
if (expected.isInstance(c))
41
System.out.println("EXPECTED: " + expected.getName() + ", "+ c);
42
else {
43
failures++;
44
System.out.println("FAIL: Unexpected wrapped exception " + c);
45
e.printStackTrace(System.out);
46
}
47
} catch (Throwable e) {
48
failures++;
49
System.out.println("FAIL: Unexpected exception has been caught " + e);
50
e.printStackTrace(System.out);
51
}
52
System.out.println();
53
try {
54
Class.forName("Invoker").getMethod("invoke2").invoke(null);
55
System.out.println("FAIL: No exception throw, probably failed to load modified bytecodes for MethodSupplier");
56
failures++;
57
} catch (InvocationTargetException e) {
58
Throwable c = e.getCause();
59
if (expected.isInstance(c))
60
System.out.println("EXPECTED: " + expected.getName() + ", "+ c);
61
else {
62
failures++;
63
System.out.println("FAIL: Unexpected wrapped exception " + c);
64
e.printStackTrace(System.out);
65
}
66
} catch (Throwable e) {
67
failures++;
68
System.out.println("FAIL: Unexpected exception has been caught " + e);
69
e.printStackTrace(System.out);
70
}
71
System.out.println();
72
try {
73
Invoker.invoke();
74
System.out.println("FAIL: No exception throw, probably failed to load modified bytecodes for MethodSupplier");
75
failures++;
76
} catch (Throwable e) {
77
if (expected.isInstance(e))
78
System.out.println("EXPECTED: " + expected.getName() + ", "+ e);
79
else {
80
failures++;
81
System.out.println("FAIL: Unexpected exception has been caught " + e);
82
e.printStackTrace(System.out);
83
}
84
}
85
System.out.println();
86
try {
87
Invoker.invoke2();
88
System.out.println("FAIL: No exception throw, probably failed to load modified bytecodes for MethodSupplier");
89
failures++;
90
} catch (Throwable e) {
91
if (expected.isInstance(e))
92
System.out.println("EXPECTED: " + expected.getName() + ", "+ e);
93
else {
94
failures++;
95
System.out.println("FAIL: Unexpected exception has been caught " + e);
96
e.printStackTrace(System.out);
97
}
98
}
99
System.out.println();
100
if (failures > 0) {
101
System.out.println("Saw " + failures + " failures");
102
}
103
return failures;
104
}
105
}
106
107