Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/jdi/EvalArgs.java
41149 views
1
/*
2
* Copyright (c) 2002, 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
/*
25
* @test
26
* @bug 4663146
27
* @summary Arguments match no method error
28
* @comment converted from test/jdk/com/sun/jdi/EvalArgs.sh
29
*
30
* @library /test/lib
31
* @build EvalArgs
32
* @run main/othervm EvalArgs
33
*/
34
35
import lib.jdb.JdbCommand;
36
import lib.jdb.JdbTest;
37
38
/*
39
* The bug is that, for example, if a String is passed
40
* as an arg to a func where an Object is expected,
41
* "Arguments match no method" error occurs. jdb doesn't notice that this is
42
* legal because String is an instance of Object.
43
*/
44
45
class EvalArgsTarg {
46
47
static jj1 myjj1;
48
static jj2 myjj2;
49
static oranges myoranges;
50
static boolean jjboolean = true;
51
static byte jjbyte = 1;
52
static char jjchar = 'a';
53
static double jjdouble = 2.2;
54
static float jjfloat = 3.1f;
55
static int jjint = 4;
56
static long jjlong = 5;
57
static short jjshort = 6;
58
static int[] jjintArray = {7, 8};
59
static float[] jjfloatArray = {9.1f, 10.2f};
60
61
62
public static void main(String args[]) {
63
myjj1 = new jj1();
64
myjj2 = new jj2();
65
myoranges = new oranges();
66
67
// prove that these work
68
System.out.println( ffjj1(myjj1));
69
System.out.println( ffjj1(myjj2));
70
71
System.out.println("EvalArgsTarg.ffoverload(EvalArgsTarg.jjboolean) = " +
72
EvalArgsTarg.ffoverload(EvalArgsTarg.jjboolean));
73
System.out.println("EvalArgsTarg.ffoverload(EvalArgsTarg.jjbyte) = " +
74
EvalArgsTarg.ffoverload(EvalArgsTarg.jjbyte));
75
System.out.println("EvalArgsTarg.ffoverload(EvalArgsTarg.jjchar) = " +
76
EvalArgsTarg.ffoverload(EvalArgsTarg.jjchar));
77
System.out.println("EvalArgsTarg.ffoverload(EvalArgsTarg.jjdouble) = " +
78
EvalArgsTarg.ffoverload(EvalArgsTarg.jjdouble));
79
80
//This doesn't even compile
81
//System.out.println( "ffintArray(jjfloatArray) = " + ffintArray(jjfloatArray));
82
gus();
83
}
84
85
static void gus() {
86
int x = 0; // @1 breakpoint
87
}
88
89
public static String ffjj1(jj1 arg) {
90
return arg.me;
91
}
92
93
public static String ffjj2(jj2 arg) {
94
return arg.me;
95
}
96
97
static String ffboolean(boolean p1) {
98
return "ffbool: p1 = " + p1;
99
}
100
101
static String ffbyte(byte p1) {
102
return "ffbyte: p1 = " + p1;
103
}
104
105
static String ffchar(char p1) {
106
return "ffchar: p1 = " + p1;
107
}
108
109
static String ffdouble(double p1) {
110
return "ffdouble: p1 = " + p1;
111
}
112
113
static String fffloat(float p1) {
114
return "fffloat: p1 = " + p1;
115
}
116
117
static String ffint(int p1) {
118
return "ffint: p1 = " + p1;
119
}
120
121
static String fflong(long p1) {
122
return "fflong: p1 = " + p1;
123
}
124
125
static String ffshort(short p1) {
126
return "ffshort: p1 = " + p1;
127
}
128
129
static String ffintArray(int[] p1) {
130
return "ffintArray: p1 = " + p1;
131
}
132
133
// Overloaded funcs
134
public static String ffoverload(jj1 arg) {
135
return arg.me;
136
}
137
138
static String ffoverload(boolean p1) {
139
return "ffoverload: boolean p1 = " + p1;
140
}
141
/***
142
static String ffoverload(byte p1) {
143
return "ffoverload: byte p1 = " + p1;
144
}
145
***/
146
static String ffoverload(char p1) {
147
return "ffoverload: char p1 = " + p1;
148
}
149
150
static String ffoverload(double p1) {
151
return "ffoverload: double p1 = " + p1;
152
}
153
154
static String ffoverload(float p1) {
155
return "ffoverload: float p1 = " + p1;
156
}
157
/***
158
static String ffoverload(int p1) {
159
return "ffoverload: int p1 = " + p1;
160
}
161
***/
162
static String ffoverload(long p1) {
163
return "ffoverload: long p1 = " + p1;
164
}
165
166
static String ffoverload(short p1) {
167
return "ffoverload: short p1 = " + p1;
168
}
169
170
static String ffoverload(int[] p1) {
171
return "ffoverload: int array p1 = " + p1;
172
}
173
174
static class jj1 {
175
String me;
176
jj1() {
177
me = "jj1name";
178
}
179
public String toString() {
180
return me;
181
}
182
183
}
184
185
static class jj2 extends jj1 {
186
jj2() {
187
super();
188
me = "jj2name";
189
}
190
}
191
192
static class oranges {
193
oranges() {
194
}
195
}
196
}
197
198
public class EvalArgs extends JdbTest {
199
public static void main(String argv[]) {
200
new EvalArgs().run();
201
}
202
203
private EvalArgs() {
204
super(DEBUGGEE_CLASS);
205
}
206
207
private static final String DEBUGGEE_CLASS = EvalArgsTarg.class.getName();
208
209
@Override
210
protected void runCases() {
211
setBreakpointsFromTestSource("EvalArgs.java", 1);
212
// Run to breakpoint #1
213
jdb.command(JdbCommand.run());
214
215
final String argsMatchNoMethod = "Arguments match no method";
216
// verify that it works ok when arg types are the same as
217
// the param types
218
evalShouldNotContain("EvalArgsTarg.ffboolean(EvalArgsTarg.jjboolean)", argsMatchNoMethod);
219
evalShouldNotContain("EvalArgsTarg.ffbyte(EvalArgsTarg.jjbyte)", argsMatchNoMethod);
220
evalShouldNotContain("EvalArgsTarg.ffchar(EvalArgsTarg.jjchar)", argsMatchNoMethod);
221
evalShouldNotContain("EvalArgsTarg.ffdouble(EvalArgsTarg.jjdouble)", argsMatchNoMethod);
222
evalShouldNotContain("EvalArgsTarg.fffloat(EvalArgsTarg.jjfloat)", argsMatchNoMethod);
223
evalShouldNotContain("EvalArgsTarg.ffint(EvalArgsTarg.jjint)", argsMatchNoMethod);
224
evalShouldNotContain("EvalArgsTarg.fflong(EvalArgsTarg.jjlong)", argsMatchNoMethod);
225
evalShouldNotContain("EvalArgsTarg.ffshort(EvalArgsTarg.jjshort)", argsMatchNoMethod);
226
evalShouldNotContain("EvalArgsTarg.ffintArray(EvalArgsTarg.jjintArray)", argsMatchNoMethod);
227
evalShouldNotContain("EvalArgsTarg.ffjj1(EvalArgsTarg.myjj1)", argsMatchNoMethod);
228
229
// Provide a visual break in the output
230
jdb.command(JdbCommand.print("1"));
231
232
// Verify mixing primitive types works ok
233
// These should work even though the arg types are
234
// not the same because there is only one
235
// method with each name.
236
evalShouldNotContain("EvalArgsTarg.ffbyte(EvalArgsTarg.jjint)", argsMatchNoMethod);
237
evalShouldNotContain("EvalArgsTarg.ffchar(EvalArgsTarg.jjdouble)", argsMatchNoMethod);
238
evalShouldNotContain("EvalArgsTarg.ffdouble(EvalArgsTarg.jjfloat)", argsMatchNoMethod);
239
evalShouldNotContain("EvalArgsTarg.fffloat(EvalArgsTarg.jjshort)", argsMatchNoMethod);
240
evalShouldNotContain("EvalArgsTarg.ffint(EvalArgsTarg.jjlong)", argsMatchNoMethod);
241
evalShouldNotContain("EvalArgsTarg.fflong(EvalArgsTarg.jjchar)", argsMatchNoMethod);
242
evalShouldNotContain("EvalArgsTarg.ffshort(EvalArgsTarg.jjbyte)", argsMatchNoMethod);
243
244
jdb.command(JdbCommand.print("1"));
245
246
// Verify that passing a subclass object works
247
evalShouldNotContain("EvalArgsTarg.ffjj1(EvalArgsTarg.myjj2)", argsMatchNoMethod);
248
evalShouldNotContain("EvalArgsTarg.myjj1.toString().equals(\"jj1name\")", argsMatchNoMethod);
249
250
jdb.command(JdbCommand.print("1"));
251
252
// Overloaded methods. These should pass
253
// because there is an exact match.
254
evalShouldNotContain("EvalArgsTarg.ffoverload(EvalArgsTarg.jjboolean)", argsMatchNoMethod);
255
256
evalShouldNotContain("EvalArgsTarg.ffoverload(EvalArgsTarg.jjchar)", argsMatchNoMethod);
257
evalShouldNotContain("EvalArgsTarg.ffoverload(EvalArgsTarg.jjdouble)", argsMatchNoMethod);
258
evalShouldNotContain("EvalArgsTarg.ffoverload(EvalArgsTarg.jjfloat)", argsMatchNoMethod);
259
evalShouldNotContain("EvalArgsTarg.ffoverload(EvalArgsTarg.jjlong)", argsMatchNoMethod);
260
evalShouldNotContain("EvalArgsTarg.ffoverload(EvalArgsTarg.jjshort)", argsMatchNoMethod);
261
evalShouldNotContain("EvalArgsTarg.ffoverload(EvalArgsTarg.jjintArray)", argsMatchNoMethod);
262
evalShouldNotContain("EvalArgsTarg.ffoverload(EvalArgsTarg.myjj1)", argsMatchNoMethod);
263
evalShouldNotContain("EvalArgsTarg.ffoverload(EvalArgsTarg.myjj2)", argsMatchNoMethod);
264
265
jdb.command(JdbCommand.print("1"));
266
jdb.command(JdbCommand.print("\"These should fail with msg Arguments match multiple methods\""));
267
268
// These overload calls should fail because there
269
// isn't an exact match and jdb isn't smart enough
270
// to figure out which of several possibilities
271
// should be called
272
final String argsMatchMultipleMethods = "Arguments match multiple methods";
273
evalShouldContain("EvalArgsTarg.ffoverload(EvalArgsTarg.jjbyte)", argsMatchMultipleMethods);
274
275
evalShouldContain("EvalArgsTarg.ffoverload(EvalArgsTarg.jjint)", argsMatchMultipleMethods);
276
277
jdb.command(JdbCommand.print("1"));
278
jdb.command(JdbCommand.print("\"These should fail with InvalidTypeExceptions\""));
279
280
final String invalidTypeException = "InvalidTypeException";
281
evalShouldContain("EvalArgsTarg.ffboolean(EvalArgsTarg.jjbyte)", invalidTypeException);
282
evalShouldContain("EvalArgsTarg.ffintArray(EvalArgsTarg.jjint)", invalidTypeException);
283
evalShouldContain("EvalArgsTarg.ffintArray(EvalArgsTarg.jjfloatArray)", invalidTypeException);
284
evalShouldContain("EvalArgsTarg.ffjj2(EvalArgsTarg.myjj1)", invalidTypeException);
285
evalShouldContain("EvalArgsTarg.ffjj2(EvalArgsTarg.myoranges)", invalidTypeException);
286
287
jdb.contToExit(1);
288
}
289
290
}
291
292