Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/XMLDecoder/spec/TestMethod.java
41155 views
1
/*
2
* Copyright (c) 2008, 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
* @summary Tests <method> element
27
* @run main/othervm -Djava.security.manager=allow TestMethod
28
* @author Sergey Malenkov
29
*/
30
31
import java.beans.XMLDecoder;
32
33
public final class TestMethod extends AbstractTest {
34
public static final String XML
35
= "<java>\n"
36
+ " <new class=\"TestMethod$A\">\n"
37
+ " <method name=\"m\">\n"
38
+ " <new class=\"TestMethod$Y\"/>\n"
39
+ " <new class=\"TestMethod$Y\"/>\n"
40
+ " </method>\n"
41
+ " </new>\n"
42
+ " <new class=\"TestMethod$B\">\n"
43
+ " <method name=\"m\">\n"
44
+ " <new class=\"TestMethod$Y\"/>\n"
45
+ " <new class=\"TestMethod$Y\"/>\n"
46
+ " </method>\n"
47
+ " </new>\n"
48
+ " <new class=\"TestMethod$C\">\n"
49
+ " <method name=\"m\">\n"
50
+ " <new class=\"TestMethod$Z\"/>\n"
51
+ " <new class=\"TestMethod$Z\"/>\n"
52
+ " </method>\n"
53
+ " </new>\n"
54
+ " <new class=\"TestMethod$D\">\n"
55
+ " <method name=\"m\">\n"
56
+ " <new class=\"TestMethod$Z\"/>\n"
57
+ " <new class=\"TestMethod$Z\"/>\n"
58
+ " </method>\n"
59
+ " </new>\n"
60
+ " <new class=\"TestMethod$E\">\n"
61
+ " <method name=\"m\">\n"
62
+ " <new class=\"TestMethod$Z\"/>\n"
63
+ " <new class=\"TestMethod$Z\"/>\n"
64
+ " </method>\n"
65
+ " </new>\n"
66
+ "</java>";
67
68
public static void main(String[] args) {
69
new TestMethod().test(true);
70
}
71
72
private NoSuchMethodException exception;
73
74
@Override
75
public void exceptionThrown(Exception exception) {
76
if (this.exception != null) {
77
// only one exception allowed
78
super.exceptionThrown(exception);
79
} else if (exception instanceof NoSuchMethodException) {
80
// expected exception: ambiguous methods are found
81
this.exception = (NoSuchMethodException) exception;
82
} else {
83
super.exceptionThrown(exception);
84
}
85
}
86
87
@Override
88
protected void validate(XMLDecoder decoder) {
89
this.exception = null;
90
validate(decoder, A.class);
91
validate(decoder, B.class);
92
validate(decoder, C.class);
93
validate(decoder, D.class);
94
validate(decoder, E.class);
95
if (this.exception == null) {
96
throw new Error("NoSuchMethodException expected");
97
}
98
}
99
100
private static void validate(XMLDecoder decoder, Class type) {
101
if (!type.equals(decoder.readObject().getClass())) {
102
throw new Error("unexpected class");
103
}
104
}
105
106
/**
107
* All ambiguous method declarations should fail.
108
*/
109
public static class A {
110
public void m(X x1, X x2) {
111
throw new Error("A.m(X,X) should not be called");
112
}
113
114
public void m(X x1, Y y2) {
115
throw new Error("A.m(X,Y) should not be called");
116
}
117
118
public void m(Y y1, X x2) {
119
throw new Error("A.m(Y,X) should not be called");
120
}
121
}
122
123
/**
124
* The most specific method in this case would be the second declaration.
125
*/
126
public static class B {
127
public void m(X x1, X x2) {
128
throw new Error("B.m(X,X) should not be called");
129
}
130
131
public void m(X x1, Y y2) {
132
// expected: B.m(X,Y) should be called
133
}
134
}
135
136
/**
137
* The most specific method in this case would be the first declaration.
138
*/
139
public static class C {
140
public void m(Y y1, Y y2) {
141
// expected: C.m(Y,Y) should be called
142
}
143
144
public void m(X x1, X x2) {
145
throw new Error("C.m(X,X) should not be called");
146
}
147
}
148
149
/**
150
* Same as the previous case but flip methods.
151
*/
152
public static class D {
153
public void m(X x1, X x2) {
154
throw new Error("D.m(X,X) should not be called");
155
}
156
157
public void m(Y y1, Y y2) {
158
// expected: D.m(Y,Y) should be called
159
}
160
}
161
162
/**
163
* The method should be called with (Z,Z).
164
*/
165
public static class E {
166
public void m(X x1, X x2) {
167
// expected: E.m(X,X) should be called
168
}
169
}
170
171
public static class X {
172
}
173
174
public static class Y extends X {
175
}
176
177
public static class Z extends Y {
178
}
179
}
180
181