2
|
1 |
#!/bin/sh
|
|
2 |
|
|
3 |
#
|
|
4 |
# Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
|
|
5 |
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
6 |
#
|
|
7 |
# This code is free software; you can redistribute it and/or modify it
|
|
8 |
# under the terms of the GNU General Public License version 2 only, as
|
|
9 |
# published by the Free Software Foundation.
|
|
10 |
#
|
|
11 |
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
# version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
# accompanied this code).
|
|
16 |
#
|
|
17 |
# You should have received a copy of the GNU General Public License version
|
|
18 |
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
#
|
|
21 |
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
# CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
# have any questions.
|
|
24 |
#
|
|
25 |
|
|
26 |
# @test
|
|
27 |
# @bug 4663146
|
|
28 |
# @summary Arguments match no method error
|
|
29 |
# @author Jim Holmlund/Suvasis
|
|
30 |
#
|
|
31 |
# @run shell/timeout=300 EvalArgs.sh
|
|
32 |
|
|
33 |
# The bug is that, for example, if a String is passed
|
|
34 |
# as an arg to a func where an Object is expected,
|
|
35 |
# the above error occurs. jdb doesnt notice that this is
|
|
36 |
# legal because String is an instance of Object.
|
|
37 |
|
|
38 |
|
|
39 |
# These are variables that can be set to control execution
|
|
40 |
|
|
41 |
#pkg=untitled7
|
|
42 |
classname=EvalArgs
|
|
43 |
#compileOptions=-g
|
|
44 |
#java="java_g"
|
|
45 |
|
|
46 |
createJavaFile()
|
|
47 |
{
|
|
48 |
cat <<EOF > $classname.java.1
|
|
49 |
public class $classname {
|
|
50 |
|
|
51 |
static jj1 myjj1;
|
|
52 |
static jj2 myjj2;
|
|
53 |
static oranges myoranges;
|
|
54 |
static boolean jjboolean = true;
|
|
55 |
static byte jjbyte = 1;
|
|
56 |
static char jjchar = 'a';
|
|
57 |
static double jjdouble = 2.2;
|
|
58 |
static float jjfloat = 3.1f;
|
|
59 |
static int jjint = 4;
|
|
60 |
static long jjlong = 5;
|
|
61 |
static short jjshort = 6;
|
|
62 |
static int[] jjintArray = {7, 8};
|
|
63 |
static float[] jjfloatArray = {9.1f, 10.2f};
|
|
64 |
|
|
65 |
|
|
66 |
public static void main(String args[]) {
|
|
67 |
myjj1 = new jj1();
|
|
68 |
myjj2 = new jj2();
|
|
69 |
myoranges = new oranges();
|
|
70 |
|
|
71 |
// prove that these work
|
|
72 |
System.out.println( ffjj1(myjj1));
|
|
73 |
System.out.println( ffjj1(myjj2));
|
|
74 |
|
|
75 |
System.out.println("$classname.ffoverload($classname.jjboolean) = " +
|
|
76 |
$classname.ffoverload($classname.jjboolean));
|
|
77 |
System.out.println("$classname.ffoverload($classname.jjbyte) = " +
|
|
78 |
$classname.ffoverload($classname.jjbyte));
|
|
79 |
System.out.println("$classname.ffoverload($classname.jjchar) = " +
|
|
80 |
$classname.ffoverload($classname.jjchar));
|
|
81 |
System.out.println("$classname.ffoverload($classname.jjdouble) = " +
|
|
82 |
$classname.ffoverload($classname.jjdouble));
|
|
83 |
|
|
84 |
|
|
85 |
//This doesn't even compile
|
|
86 |
//System.out.println( "ffintArray(jjfloatArray) = " + ffintArray(jjfloatArray));
|
|
87 |
gus();
|
|
88 |
}
|
|
89 |
|
|
90 |
static void gus() {
|
|
91 |
int x = 0; // @1 breakpoint
|
|
92 |
}
|
|
93 |
|
|
94 |
public static String ffjj1(jj1 arg) {
|
|
95 |
return arg.me;
|
|
96 |
}
|
|
97 |
|
|
98 |
public static String ffjj2(jj2 arg) {
|
|
99 |
return arg.me;
|
|
100 |
}
|
|
101 |
|
|
102 |
static String ffboolean(boolean p1) {
|
|
103 |
return "ffbool: p1 = " + p1;
|
|
104 |
}
|
|
105 |
|
|
106 |
static String ffbyte(byte p1) {
|
|
107 |
return "ffbyte: p1 = " + p1;
|
|
108 |
}
|
|
109 |
|
|
110 |
static String ffchar(char p1) {
|
|
111 |
return "ffchar: p1 = " + p1;
|
|
112 |
}
|
|
113 |
|
|
114 |
static String ffdouble(double p1) {
|
|
115 |
return "ffdouble: p1 = " + p1;
|
|
116 |
}
|
|
117 |
|
|
118 |
static String fffloat(float p1) {
|
|
119 |
return "fffloat: p1 = " + p1;
|
|
120 |
}
|
|
121 |
|
|
122 |
static String ffint(int p1) {
|
|
123 |
return "ffint: p1 = " + p1;
|
|
124 |
}
|
|
125 |
|
|
126 |
static String fflong(long p1) {
|
|
127 |
return "fflong: p1 = " + p1;
|
|
128 |
}
|
|
129 |
|
|
130 |
static String ffshort(short p1) {
|
|
131 |
return "ffshort: p1 = " + p1;
|
|
132 |
}
|
|
133 |
|
|
134 |
static String ffintArray(int[] p1) {
|
|
135 |
return "ffintArray: p1 = " + p1;
|
|
136 |
}
|
|
137 |
|
|
138 |
// Overloaded funcs
|
|
139 |
public static String ffoverload(jj1 arg) {
|
|
140 |
return arg.me;
|
|
141 |
}
|
|
142 |
|
|
143 |
static String ffoverload(boolean p1) {
|
|
144 |
return "ffoverload: boolean p1 = " + p1;
|
|
145 |
}
|
|
146 |
/***
|
|
147 |
static String ffoverload(byte p1) {
|
|
148 |
return "ffoverload: byte p1 = " + p1;
|
|
149 |
}
|
|
150 |
***/
|
|
151 |
static String ffoverload(char p1) {
|
|
152 |
return "ffoverload: char p1 = " + p1;
|
|
153 |
}
|
|
154 |
|
|
155 |
static String ffoverload(double p1) {
|
|
156 |
return "ffoverload: double p1 = " + p1;
|
|
157 |
}
|
|
158 |
|
|
159 |
static String ffoverload(float p1) {
|
|
160 |
return "ffoverload: float p1 = " + p1;
|
|
161 |
}
|
|
162 |
/***
|
|
163 |
static String ffoverload(int p1) {
|
|
164 |
return "ffoverload: int p1 = " + p1;
|
|
165 |
}
|
|
166 |
***/
|
|
167 |
static String ffoverload(long p1) {
|
|
168 |
return "ffoverload: long p1 = " + p1;
|
|
169 |
}
|
|
170 |
|
|
171 |
static String ffoverload(short p1) {
|
|
172 |
return "ffoverload: short p1 = " + p1;
|
|
173 |
}
|
|
174 |
|
|
175 |
static String ffoverload(int[] p1) {
|
|
176 |
return "ffoverload: int array p1 = " + p1;
|
|
177 |
}
|
|
178 |
|
|
179 |
static class jj1 {
|
|
180 |
String me;
|
|
181 |
jj1() {
|
|
182 |
me = "jj1name";
|
|
183 |
}
|
|
184 |
public String toString() {
|
|
185 |
return me;
|
|
186 |
}
|
|
187 |
|
|
188 |
}
|
|
189 |
|
|
190 |
static class jj2 extends jj1 {
|
|
191 |
jj2() {
|
|
192 |
super();
|
|
193 |
me = "jj2name";
|
|
194 |
}
|
|
195 |
}
|
|
196 |
|
|
197 |
static class oranges {
|
|
198 |
oranges() {
|
|
199 |
}
|
|
200 |
}
|
|
201 |
}
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
EOF
|
|
206 |
}
|
|
207 |
|
|
208 |
# drive jdb by sending cmds to it and examining its output
|
|
209 |
dojdbCmds()
|
|
210 |
{
|
|
211 |
setBkpts @1
|
|
212 |
runToBkpt @1
|
|
213 |
|
|
214 |
# verify that it works ok when arg types are the same as
|
|
215 |
# the param types
|
|
216 |
cmd eval "$classname.ffboolean($classname.jjboolean)"
|
|
217 |
cmd eval "$classname.ffbyte($classname.jjbyte)"
|
|
218 |
cmd eval "$classname.ffchar($classname.jjchar)"
|
|
219 |
cmd eval "$classname.ffdouble($classname.jjdouble)"
|
|
220 |
cmd eval "$classname.fffloat($classname.jjfloat)"
|
|
221 |
cmd eval "$classname.ffint($classname.jjint)"
|
|
222 |
cmd eval "$classname.fflong($classname.jjlong)"
|
|
223 |
cmd eval "$classname.ffshort($classname.jjshort)"
|
|
224 |
cmd eval "$classname.ffintArray($classname.jjintArray)"
|
|
225 |
cmd eval "$classname.ffjj1($classname.myjj1)"
|
|
226 |
|
|
227 |
# Provide a visual break in the output
|
|
228 |
cmd print 1
|
|
229 |
|
|
230 |
# Verify mixing primitive types works ok
|
|
231 |
# These should work even though the arg types are
|
|
232 |
# not the same because there is only one
|
|
233 |
# method with each name.
|
|
234 |
cmd eval "$classname.ffbyte($classname.jjint)"
|
|
235 |
cmd eval "$classname.ffchar($classname.jjdouble)"
|
|
236 |
cmd eval "$classname.ffdouble($classname.jjfloat)"
|
|
237 |
cmd eval "$classname.fffloat($classname.jjshort)"
|
|
238 |
cmd eval "$classname.ffint($classname.jjlong)"
|
|
239 |
cmd eval "$classname.fflong($classname.jjchar)"
|
|
240 |
cmd eval "$classname.ffshort($classname.jjbyte)"
|
|
241 |
|
|
242 |
cmd print 1
|
|
243 |
|
|
244 |
# Verify that passing a subclass object works
|
|
245 |
cmd eval "$classname.ffjj1($classname.myjj2)"
|
|
246 |
cmd eval "$classname.myjj1.toString().equals("jj1name")"
|
|
247 |
|
|
248 |
cmd print 1
|
|
249 |
|
|
250 |
# Overloaded methods. These should pass
|
|
251 |
# because there is an exact match.
|
|
252 |
cmd eval "$classname.ffoverload($classname.jjboolean)"
|
|
253 |
|
|
254 |
cmd eval "$classname.ffoverload($classname.jjchar)"
|
|
255 |
cmd eval "$classname.ffoverload($classname.jjdouble)"
|
|
256 |
cmd eval "$classname.ffoverload($classname.jjfloat)"
|
|
257 |
cmd eval "$classname.ffoverload($classname.jjlong)"
|
|
258 |
cmd eval "$classname.ffoverload($classname.jjshort)"
|
|
259 |
cmd eval "$classname.ffoverload($classname.jjintArray)"
|
|
260 |
cmd eval "$classname.ffoverload($classname.myjj1)"
|
|
261 |
cmd eval "$classname.ffoverload($classname.myjj2)"
|
|
262 |
jdbFailIfPresent "Arguments match no method"
|
|
263 |
|
|
264 |
cmd print 1
|
|
265 |
cmd print '"These should fail with msg Arguments match multiple methods"'
|
|
266 |
|
|
267 |
# These overload calls should fail because ther
|
|
268 |
# isn't an exact match and jdb isn't smart enough
|
|
269 |
# to figure out which of several possibilities
|
|
270 |
# should be called
|
|
271 |
cmd eval "$classname.ffoverload($classname.jjbyte)"
|
|
272 |
jdbFailIfNotPresent "Arguments match multiple methods" 3
|
|
273 |
|
|
274 |
cmd eval "$classname.ffoverload($classname.jjint)"
|
|
275 |
jdbFailIfNotPresent "Arguments match multiple methods" 3
|
|
276 |
|
|
277 |
cmd print 1
|
|
278 |
cmd print '"These should fail with InvalidTypeExceptions"'
|
|
279 |
|
|
280 |
cmd eval "$classname.ffboolean($classname.jjbyte)"
|
|
281 |
jdbFailIfNotPresent "InvalidTypeException" 3
|
|
282 |
|
|
283 |
cmd eval "$classname.ffintArray($classname.jjint)"
|
|
284 |
jdbFailIfNotPresent "InvalidTypeException" 3
|
|
285 |
|
|
286 |
cmd eval "$classname.ffintArray($classname.jjfloatArray)"
|
|
287 |
jdbFailIfNotPresent "InvalidTypeException" 3
|
|
288 |
|
|
289 |
cmd eval "$classname.ffjj2($classname.myjj1)"
|
|
290 |
jdbFailIfNotPresent "InvalidTypeException" 3
|
|
291 |
|
|
292 |
cmd eval "$classname.ffjj2($classname.myoranges)"
|
|
293 |
jdbFailIfNotPresent "InvalidTypeException" 3
|
|
294 |
|
|
295 |
cmd quit
|
|
296 |
}
|
|
297 |
|
|
298 |
|
|
299 |
mysetup()
|
|
300 |
{
|
|
301 |
if [ -z "$TESTSRC" ] ; then
|
|
302 |
TESTSRC=.
|
|
303 |
fi
|
|
304 |
|
|
305 |
for ii in . $TESTSRC $TESTSRC/.. ; do
|
|
306 |
if [ -r "$ii/ShellScaffold.sh" ] ; then
|
|
307 |
. $ii/ShellScaffold.sh
|
|
308 |
break
|
|
309 |
fi
|
|
310 |
done
|
|
311 |
}
|
|
312 |
|
|
313 |
# You could replace this next line with the contents
|
|
314 |
# of ShellScaffold.sh and this script will run just the same.
|
|
315 |
mysetup
|
|
316 |
|
|
317 |
runit
|
|
318 |
pass
|