Thu, 03 Feb 2011 09:36:28 +0000
5017953: spurious cascaded diagnostics when name not found
Summary: when an operator is applied to one or more erroneous operands, spurious diagnostics are generated
Reviewed-by: jjg
1 #!/bin/sh
3 #
4 # Copyright (c) 2003, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 # or visit www.oracle.com if you need additional information or have any
23 # questions.
24 #
26 #
27 # @test
28 # @bug 4758537 4809833
29 # @summary Test that javac and java find files in similar ways
30 # @author Martin Buchholz
31 #
32 # @run shell/timeout=600 MineField.sh
34 # To run this test manually, simply do ./MineField.sh
36 #----------------------------------------------------------------
37 # The search order for classes used by both java and javac is:
38 #
39 # -Xbootclasspath/p:<path>
40 # -endorseddirs <dirs> or -Djava.endorsed.dirs=<dirs> (search for jar/zip only)
41 # -bootclasspath <path> or -Xbootclasspath:<path>
42 # -Xbootclasspath/a:<path>
43 # -extdirs <dirs> or -Djava.ext.dirs=<dirs> (search for jar/zip only)
44 # -classpath <path>, -cp <path>, env CLASSPATH=<path>
45 #
46 # Peculiarities of the class file search:
47 # - Empty elements of the (user) classpath default to ".",
48 # while empty elements of other paths are ignored.
49 # - Only for the user classpath is an empty string value equivalent to "."
50 # - Specifying a bootclasspath on the command line obliterates any
51 # previous -Xbootclasspath/p: or -Xbootclasspath/a: command line flags.
52 #----------------------------------------------------------------
54 . ${TESTSRC-.}/Util.sh
56 set -u
58 BCP=`DefaultBootClassPath`
60 #----------------------------------------------------------------
61 # Prepare the "Minefield"
62 #----------------------------------------------------------------
63 Cleanup() {
64 Sys rm -rf GooSrc GooJar GooZip GooClass
65 Sys rm -rf BadSrc BadJar BadZip BadClass
66 Sys rm -rf OneDir *.class Main.java MANIFEST.MF
67 }
69 Cleanup
70 Sys mkdir GooSrc GooJar GooZip GooClass
71 Sys mkdir BadSrc BadJar BadZip BadClass
73 echo 'public class Lib {public static void f(){}}' > Lib.java
74 Sys "$javac" ${TESTTOOLVMOPTS} Lib.java
75 Sys "$jar" cf GooJar/Lib.jar Lib.class
76 Sys "$jar" cf GooZip/Lib.zip Lib.class
77 Sys mv Lib.class GooClass/.
78 Sys mv Lib.java GooSrc/.
79 CheckFiles GooZip/Lib.zip GooJar/Lib.jar GooSrc/Lib.java
81 echo 'public class Lib {/* Bad */}' > Lib.java
82 Sys "$javac" ${TESTTOOLVMOPTS} Lib.java
83 Sys "$jar" cf BadJar/Lib.jar Lib.class
84 Sys "$jar" cf BadZip/Lib.zip Lib.class
85 Sys mv Lib.class BadClass/.
86 Sys mv Lib.java BadSrc/.
87 CheckFiles BadZip/Lib.zip BadJar/Lib.jar BadSrc/Lib.java
89 echo 'public class Main {public static void main(String[] a) {Lib.f();}}' > Main.java
91 #----------------------------------------------------------------
92 # Verify that javac class search order is the same as java's
93 #----------------------------------------------------------------
94 Failure "$javac" ${TESTTOOLVMOPTS} \
95 -Xbootclasspath/p:"BadClass" \
96 -J-Djava.endorsed.dirs="GooJar" \
97 Main.java
98 Success "$javac" ${TESTTOOLVMOPTS} \
99 -Xbootclasspath/p:"GooClass${PS}BadJar/Lib.jar" \
100 -J-Djava.endorsed.dirs="BadJar${PS}GooZip" \
101 Main.java
102 Failure "$java" ${TESTVMOPTS} \
103 -Xbootclasspath/p:"BadClass" \
104 -Djava.endorsed.dirs="GooJar" \
105 Main
106 Success "$java" ${TESTVMOPTS} \
107 -Xbootclasspath/p:"GooClass${PS}BadJar/Lib.jar" \
108 -Djava.endorsed.dirs="BadJar${PS}GooZip" \
109 Main
111 #----------------------------------------------------------------
112 Failure "$javac" ${TESTTOOLVMOPTS} \
113 -Xbootclasspath/p:"GooClass" \
114 -bootclasspath "$BCP${PS}BadZip/Lib.zip" \
115 Main.java
116 Success "$javac" ${TESTTOOLVMOPTS} \
117 -Xbootclasspath/p:"BadClass${PS}GooClass" \
118 -bootclasspath "$BCP${PS}GooZip/Lib.zip${PS}BadClass" \
119 Main.java
120 Success "$javac" ${TESTTOOLVMOPTS} \
121 -Xbootclasspath/p:"BadJar/Lib.jar" \
122 -Xbootclasspath:"$BCP${PS}GooClass" \
123 Main.java
124 Failure "$java" ${TESTVMOPTS} \
125 -Xbootclasspath/p:"GooClass" \
126 -Xbootclasspath:"$BCP${PS}BadZip/Lib.zip" \
127 Main
128 Success "$java" ${TESTVMOPTS} \
129 -Xbootclasspath/p:"BadClass${PS}GooClass" \
130 -Xbootclasspath:"$BCP${PS}GooZip/Lib.zip${PS}BadClass" \
131 Main
133 #----------------------------------------------------------------
134 Failure "$javac" ${TESTTOOLVMOPTS} \
135 -bootclasspath "$BCP${PS}GooZip/Lib.zip" \
136 -Xbootclasspath/p:"BadClass" \
137 Main.java
138 Success "$javac" ${TESTTOOLVMOPTS} \
139 -bootclasspath "$BCP${PS}BadZip/Lib.zip" \
140 -Xbootclasspath/p:"GooClass${PS}BadJar/Lib.jar" \
141 Main.java
142 Failure "$java" ${TESTVMOPTS} \
143 -Xbootclasspath:"$BCP${PS}GooClass" \
144 -Xbootclasspath/p:"BadClass" \
145 Main
146 Success "$java" ${TESTVMOPTS} \
147 -Xbootclasspath:"$BCP${PS}BadClass" \
148 -Xbootclasspath/p:"GooClass${PS}BadJar/Lib.jar" \
149 Main
151 #----------------------------------------------------------------
152 Failure "$javac" ${TESTTOOLVMOPTS} \
153 -Xbootclasspath/p:"BadClass" \
154 -Xbootclasspath/a:"GooClass" \
155 Main.java
156 Success "$javac" ${TESTTOOLVMOPTS} \
157 -Xbootclasspath/p:"GooClass${PS}BadClass" \
158 -Xbootclasspath/a:"BadClass" \
159 Main.java
160 Failure "$java" ${TESTVMOPTS} \
161 -Xbootclasspath/p:"BadClass" \
162 -Xbootclasspath/a:"GooClass" \
163 Main
164 Success "$java" ${TESTVMOPTS} \
165 -Xbootclasspath/p:"GooClass${PS}BadClass" \
166 -Xbootclasspath/a:"BadClass" \
167 Main
169 #----------------------------------------------------------------
170 Failure "$javac" ${TESTTOOLVMOPTS} \
171 -Xbootclasspath/p:"GooClass" \
172 -J-Djava.endorsed.dirs="BadZip" \
173 -bootclasspath "GooClass${PS}$BCP" \
174 Main.java
175 Success "$javac" ${TESTTOOLVMOPTS} \
176 -Xbootclasspath/p:"BadClass" \
177 -J-Djava.endorsed.dirs="BadClass${PS}GooZip${PS}BadJar" \
178 -bootclasspath "BadClass${PS}$BCP" \
179 Main.java
180 Failure "$java" ${TESTVMOPTS} \
181 -Xbootclasspath/p:"GooClass" \
182 -Djava.endorsed.dirs="BadZip" \
183 -Xbootclasspath:"GooClass${PS}$BCP" \
184 Main
185 Success "$java" ${TESTVMOPTS} \
186 -Xbootclasspath/p:"BadClass" \
187 -Djava.endorsed.dirs="BadClass${PS}GooZip${PS}BadJar" \
188 -Xbootclasspath:"BadClass${PS}$BCP" \
189 Main
191 #----------------------------------------------------------------
192 Failure "$javac" ${TESTTOOLVMOPTS} \
193 -Xbootclasspath/p:"GooClass" \
194 -Xbootclasspath:"BadClass${PS}$BCP" \
195 -Xbootclasspath/a:"GooClass" \
196 Main.java
197 Success "$javac" ${TESTTOOLVMOPTS} \
198 -Xbootclasspath/p:"BadClass" \
199 -Xbootclasspath:"GooClass${PS}BadClass${PS}$BCP" \
200 -Xbootclasspath/a:"BadClass" \
201 Main.java
202 Failure "$java" ${TESTVMOPTS} \
203 -Xbootclasspath/p:"GooClass" \
204 -Xbootclasspath:"BadClass${PS}$BCP" \
205 -Xbootclasspath/a:"GooClass" \
206 Main
207 Success "$java" ${TESTVMOPTS} \
208 -Xbootclasspath/p:"BadClass" \
209 -Xbootclasspath:"GooClass${PS}BadClass${PS}$BCP" \
210 -Xbootclasspath/a:"BadClass" \
211 Main
213 #----------------------------------------------------------------
214 Failure "$javac" ${TESTTOOLVMOPTS} \
215 -J-Djava.endorsed.dirs="BadZip" \
216 -Xbootclasspath:"GooClass${PS}$BCP" \
217 Main.java
218 Success "$javac" ${TESTTOOLVMOPTS} \
219 -endorseddirs "BadClass${PS}GooZip${PS}BadJar" \
220 -Xbootclasspath:"BadClass${PS}$BCP" \
221 Main.java
222 Success "$javac" ${TESTTOOLVMOPTS} \
223 -Djava.endorsed.dirs="BadClass${PS}GooZip${PS}BadJar" \
224 -Xbootclasspath:"BadClass${PS}$BCP" \
225 Main.java
226 Success "$javac" ${TESTTOOLVMOPTS} \
227 -J-Djava.endorsed.dirs="BadClass${PS}GooZip${PS}BadJar" \
228 -Xbootclasspath:"BadClass${PS}$BCP" \
229 Main.java
230 Failure "$java" ${TESTVMOPTS} \
231 -Djava.endorsed.dirs="BadZip" \
232 -Xbootclasspath:"GooClass${PS}$BCP" \
233 Main
234 Success "$java" ${TESTVMOPTS} \
235 -Djava.endorsed.dirs="BadClass${PS}GooZip${PS}BadJar" \
236 -Xbootclasspath:"BadClass${PS}$BCP" \
237 Main
239 #----------------------------------------------------------------
240 Failure "$javac" ${TESTTOOLVMOPTS} \
241 -Xbootclasspath/a:"BadClass" \
242 -extdirs "GooZip" \
243 Main.java
244 Success "$javac" ${TESTTOOLVMOPTS} \
245 -Xbootclasspath/a:"GooClass${PS}BadClass" \
246 -extdirs "BadZip" \
247 Main.java
248 Failure "$java" ${TESTVMOPTS} \
249 -Xbootclasspath/a:"BadClass" \
250 -Djava.ext.dirs="GooZip" \
251 Main
252 Success "$java" ${TESTVMOPTS} \
253 -Xbootclasspath/a:"GooClass${PS}BadClass" \
254 -Djava.ext.dirs="BadZip" \
255 Main
257 #----------------------------------------------------------------
258 Failure "$javac" ${TESTTOOLVMOPTS} \
259 -bootclasspath "$BCP${PS}BadJar/Lib.jar" \
260 -J-Djava.ext.dir="GooJar" \
261 Main.java
262 Success "$javac" ${TESTTOOLVMOPTS} \
263 -bootclasspath "$BCP${PS}GooJar/Lib.jar${PS}BadClass" \
264 -J-Djava.ext.dir="BadJar" \
265 Main.java
266 Failure "$java" ${TESTVMOPTS} \
267 -Xbootclasspath:"$BCP${PS}BadJar/Lib.jar" \
268 -Djava.ext.dirs="GooJar" \
269 Main
270 Success "$java" ${TESTVMOPTS} \
271 -Xbootclasspath:"$BCP${PS}GooJar/Lib.jar${PS}BadClass" \
272 -Djava.ext.dirs="BadJar" \
273 Main
275 #----------------------------------------------------------------
276 Failure "$javac" ${TESTTOOLVMOPTS} \
277 -extdirs "GooClass${PS}BadZip" \
278 -cp "GooZip/Lib.zip" \
279 Main.java
280 Success "$javac" ${TESTTOOLVMOPTS} \
281 -extdirs "BadClass${PS}GooZip${PS}BadJar" \
282 -cp "BadZip/Lib.zip" \
283 Main.java
284 Success "$javac" ${TESTTOOLVMOPTS} \
285 -Djava.ext.dirs="GooZip${PS}BadJar" \
286 -classpath "BadZip/Lib.zip" \
287 Main.java
288 Success "$javac" ${TESTTOOLVMOPTS} \
289 -J-Djava.ext.dirs="GooZip${PS}BadJar" \
290 -classpath "BadZip/Lib.zip" \
291 Main.java
292 Failure "$java" ${TESTVMOPTS} \
293 -Djava.ext.dirs="GooClass${PS}BadZip" \
294 -cp "GooZip/Lib.zip${PS}." \
295 Main
296 Success "$java" ${TESTVMOPTS} \
297 -Djava.ext.dirs="GooZip${PS}BadJar" \
298 -cp "BadZip/Lib.zip${PS}." \
299 Main
301 #----------------------------------------------------------------
302 Failure "$javac" ${TESTTOOLVMOPTS} -classpath "BadClass${PS}GooClass" Main.java
303 Success "$javac" ${TESTTOOLVMOPTS} -classpath "GooClass${PS}BadClass" Main.java
304 Failure "$java" ${TESTVMOPTS} -classpath "BadClass${PS}GooClass${PS}." Main
305 Success "$java" ${TESTVMOPTS} -classpath "GooClass${PS}BadClass${PS}." Main
307 Failure "$javac" ${TESTTOOLVMOPTS} -cp "BadJar/Lib.jar${PS}GooZip/Lib.zip" Main.java
308 Success "$javac" ${TESTTOOLVMOPTS} -cp "GooJar/Lib.jar${PS}BadZip/Lib.zip" Main.java
309 Failure "$java" ${TESTVMOPTS} -cp "BadJar/Lib.jar${PS}${PS}GooZip/Lib.zip" Main
310 Success "$java" ${TESTVMOPTS} -cp "GooJar/Lib.jar${PS}${PS}BadZip/Lib.zip" Main
312 Failure env CLASSPATH="BadZip/Lib.zip${PS}GooJar/Lib.jar" "$javac" ${TESTTOOLVMOPTS} Main.java
313 Success env CLASSPATH="GooZip/Lib.zip${PS}BadJar/Lib.jar" "$javac" ${TESTTOOLVMOPTS} Main.java
314 Failure env CLASSPATH="${PS}BadZip/Lib.zip${PS}GooJar/Lib.jar" "$java" ${TESTVMOPTS} Main
315 Success env CLASSPATH="${PS}GooZip/Lib.zip${PS}BadJar/Lib.jar" "$java" ${TESTVMOPTS} Main
317 #----------------------------------------------------------------
318 # Check behavior of empty paths and empty path elements
319 #----------------------------------------------------------------
320 In() { cd "$1"; shift; "$@"; cd ..; }
322 In GooClass Failure "$javac" ${TESTTOOLVMOPTS} -cp ".." ../Main.java
323 In GooClass Failure "$java" ${TESTVMOPTS} -cp ".." Main
325 # Unspecified classpath defaults to "."
326 Sys mkdir OneDir; Sys cp -p Main.java GooClass/Lib.class OneDir/.
327 In OneDir Success "$javac" ${TESTTOOLVMOPTS} Main.java
328 In OneDir Success "$java" ${TESTVMOPTS} Main
330 # Empty classpath elements mean "."
331 In GooClass Success "$javac" ${TESTTOOLVMOPTS} -cp "${PS}.." ../Main.java
332 In GooClass Success "$java" ${TESTVMOPTS} -cp "${PS}.." Main
334 In GooClass Success "$javac" ${TESTTOOLVMOPTS} -cp "..${PS}" ../Main.java
335 In GooClass Success "$java" ${TESTVMOPTS} -cp "..${PS}" Main
337 In GooClass Success "$javac" ${TESTTOOLVMOPTS} -cp "..${PS}${PS}/xyzzy" ../Main.java
338 In GooClass Success "$java" ${TESTVMOPTS} -cp "..${PS}${PS}/xyzzy" Main
340 # All other empty path elements are ignored.
341 In GooJar Failure "$javac" ${TESTTOOLVMOPTS} -extdirs "" -cp ".." ../Main.java
342 In GooJar Failure "$java" ${TESTVMOPTS} -Djava.ext.dirs="" -cp ".." Main
344 In GooJar Failure "$javac" ${TESTTOOLVMOPTS} -extdirs "${PS}" -cp ".." ../Main.java
345 In GooJar Failure "$javac" ${TESTTOOLVMOPTS} -Djava.ext.dirs="${PS}" -cp ".." ../Main.java
346 In GooJar Failure "$java" ${TESTVMOPTS} -Djava.ext.dirs="${PS}" -cp ".." Main
348 In GooJar Success "$javac" ${TESTTOOLVMOPTS} -extdirs "." -cp ".." ../Main.java
349 In GooJar Success "$javac" ${TESTTOOLVMOPTS} -Djava.ext.dirs="." -cp ".." ../Main.java
350 In GooJar Success "$java" ${TESTVMOPTS} -Djava.ext.dirs="." -cp ".." Main
352 In GooJar Failure "$javac" ${TESTTOOLVMOPTS} -J-Djava.endorsed.dirs="" -cp ".." ../Main.java
353 In GooJar Failure "$javac" ${TESTTOOLVMOPTS} -Djava.endorsed.dirs="" -cp ".." ../Main.java
354 In GooJar Failure "$java" ${TESTVMOPTS} -Djava.endorsed.dirs="" -cp ".." Main
356 In GooJar Failure "$javac" ${TESTTOOLVMOPTS} -J-Djava.endorsed.dirs="${PS}" -cp ".." ../Main.java
357 In GooJar Failure "$javac" ${TESTTOOLVMOPTS} -endorseddirs "${PS}" -cp ".." ../Main.java
358 In GooJar Failure "$java" ${TESTVMOPTS} -Djava.endorsed.dirs="${PS}" -cp ".." Main
360 In GooJar Success "$javac" ${TESTTOOLVMOPTS} -J-Djava.endorsed.dirs="." -cp ".." ../Main.java
361 In GooJar Success "$javac" ${TESTTOOLVMOPTS} -Djava.endorsed.dirs="." -cp ".." ../Main.java
362 In GooJar Success "$java" ${TESTVMOPTS} -Djava.endorsed.dirs="." -cp ".." Main
364 In GooClass Failure "$javac" ${TESTTOOLVMOPTS} -Xbootclasspath/p: -cp ".." ../Main.java
365 In GooClass Failure "$java" ${TESTVMOPTS} -Xbootclasspath/p: -cp ".." Main
367 In GooClass Success "$javac" ${TESTTOOLVMOPTS} -Xbootclasspath/p:. -cp ".." ../Main.java
368 In GooClass Success "$java" ${TESTVMOPTS} -Xbootclasspath/p:. -cp ".." Main
370 In GooClass Failure "$javac" ${TESTTOOLVMOPTS} -Xbootclasspath:"$BCP" -cp ".." ../Main.java
371 In GooClass Failure "$java" ${TESTVMOPTS} -Xbootclasspath:"$BCP" -cp ".." Main
373 In GooClass Success "$javac" ${TESTTOOLVMOPTS} -Xbootclasspath:"$BCP${PS}." -cp ".." ../Main.java
374 In GooClass Success "$java" ${TESTVMOPTS} -Xbootclasspath:"$BCP${PS}." -cp ".." Main
376 In GooClass Failure "$javac" ${TESTTOOLVMOPTS} -Xbootclasspath/a: -cp ".." ../Main.java
377 In GooClass Failure "$java" ${TESTVMOPTS} -Xbootclasspath/a: -cp ".." Main
379 In GooClass Success "$javac" ${TESTTOOLVMOPTS} -Xbootclasspath/a:. -cp ".." ../Main.java
380 In GooClass Success "$java" ${TESTVMOPTS} -Xbootclasspath/a:. -cp ".." Main
382 Cleanup
384 Bottom Line