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, 2006, 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 4884487 6295519 6236704 6429613
29 # @summary Test for proper diagnostics during path manipulation operations
30 # @author Martin Buchholz
31 #
32 # @run shell/timeout=180 Diagnostics.sh
34 # To run this test manually, simply do ./Diagnostics.sh
36 . ${TESTSRC-.}/Util.sh
38 set -u
40 BCP=`DefaultBootClassPath`
42 DiagnosticsInEnglishPlease
44 No() { NO="no"; "$@"; NO=""; } # No means NO!
46 Warning() {
47 HorizontalRule
48 echo "$@"
49 output=`"$@" 2>&1`; rc="$?"
50 test -n "$output" && echo "$output"
51 test $rc -eq 0 || Fail "Command \"$*\" failed with exitValue $rc";
52 case "$output" in *warning:*) gotwarning="yes";; *) gotwarning="no";; esac
54 if test "$gotwarning" = "yes" -a "$NO" = "no"; then
55 Fail "Command \"$*\" printed an unexpected warning"
56 elif test "$gotwarning" = "no" -a "$NO" != "no"; then
57 Fail "Command \"$*\" did not generate the expected warning"
58 fi
59 }
61 Error() {
62 HorizontalRule
63 echo "$@"
64 output=`"$@" 2>&1`; rc="$?"
65 test -n "$output" && echo "$output"
66 case "$output" in *error:*) goterror="yes";; *) goterror="no";; esac
68 if test "$NO" = "no"; then
69 test "$rc" -ne 0 && \
70 Fail "Command \"$*\" failed with return code $rc"
71 test "$goterror" = "yes" && \
72 Fail "Command \"$*\" did not generate any error message"
73 else
74 test "$rc" -eq 0 && \
75 Fail "Command \"$*\" was supposed to Die with fatal error";
76 test "$goterror" = "no" && \
77 Fail "Command \"$*\" printed an unexpected error message"
78 fi
79 }
81 Cleanup() {
82 Sys rm -rf Main.java Main.class
83 Sys rm -rf classes classes.foo classes.jar classes.war classes.zip
84 Sys rm -rf MANIFEST.MF classesRef.jar classesRefRef.jar jars
85 }
87 Cleanup
88 echo "public class Main{public static void main(String[]a){}}" > Main.java
90 #----------------------------------------------------------------
91 # No warnings unless -Xlint:path is used
92 #----------------------------------------------------------------
93 No Warning "$javac" ${TESTTOOLVMOPTS} Main.java
94 No Warning "$javac" ${TESTTOOLVMOPTS} -cp ".${PS}classes" Main.java
96 #----------------------------------------------------------------
97 # Warn for missing elts in user-specified paths
98 #----------------------------------------------------------------
99 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes" Main.java
100 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-Xbootclasspath/p:classes" Main.java
101 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint "-Xbootclasspath/a:classes" Main.java
102 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-endorseddirs" "classes" Main.java
103 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint "-extdirs" "classes" Main.java
104 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-Xbootclasspath:classes${PS}${BCP}" Main.java
106 #----------------------------------------------------------------
107 # No warning for missing elts in "system" paths
108 #----------------------------------------------------------------
109 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Djava.endorsed.dirs=classes" Main.java
110 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Djava.ext.dirs=classes" Main.java
111 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Xbootclasspath/p:classes" Main.java
112 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Xbootclasspath/a:classes" Main.java
113 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Xbootclasspath:classes${PS}${BCP}" Main.java
115 #----------------------------------------------------------------
116 # No warning if class path element exists
117 #----------------------------------------------------------------
118 Sys mkdir classes
119 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes" Main.java
120 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-endorseddirs" "classes" Main.java
121 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-extdirs" "classes" Main.java
122 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-Xbootclasspath/p:classes" Main.java
123 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-Xbootclasspath/a:classes" Main.java
124 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-Xbootclasspath:classes${PS}${BCP}" Main.java
126 Sys "$jar" cf classes.jar Main.class
127 Sys cp classes.jar classes.war
128 Sys cp classes.war classes.zip
129 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes.jar" Main.java
130 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes.war" Main.java
131 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes.zip" Main.java
133 #----------------------------------------------------------------
134 # Warn if -Xlint is used and if class path element refers to
135 # regular file which doesn't look like a zip file, but is
136 #----------------------------------------------------------------
137 Sys cp classes.war classes.foo
138 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes.foo" Main.java
141 #----------------------------------------------------------------
142 # No error if class path element refers to regular file which is
143 # not a zip file
144 #----------------------------------------------------------------
145 No Error "$javac" ${TESTTOOLVMOPTS} -cp Main.java Main.java # Main.java is NOT a jar file
146 No Error "$javac" ${TESTTOOLVMOPTS} Main.java
148 #----------------------------------------------------------------
149 # Warn if -Xlint is used and if class path element refers to
150 # regular file which is not a zip file
151 #----------------------------------------------------------------
152 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -cp Main.java Main.java # Main.java is NOT a jar file
154 #----------------------------------------------------------------
155 # Test jar file class path reference recursion
156 #----------------------------------------------------------------
157 MkManifestWithClassPath classesRef.jar
158 Sys "$jar" cmf MANIFEST.MF classesRefRef.jar Main.class
160 #----------------------------------------------------------------
161 # Non-existent recursive Class-Path reference gives warning
162 #----------------------------------------------------------------
163 No Warning "$javac" ${TESTTOOLVMOPTS} -classpath classesRefRef.jar Main.java
164 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -classpath classesRefRef.jar Main.java
165 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -Xbootclasspath/p:classesRefRef.jar Main.java
167 BadJarFile classesRef.jar
169 #----------------------------------------------------------------
170 # Non-jar file recursive Class-Path reference gives error
171 #----------------------------------------------------------------
172 Error "$javac" ${TESTTOOLVMOPTS} -classpath classesRefRef.jar Main.java
173 No Error "$javac" ${TESTTOOLVMOPTS} -Xbootclasspath/a:classesRefRef.jar Main.java
175 MkManifestWithClassPath classes
176 Sys "$jar" cmf MANIFEST.MF classesRef.jar Main.class
178 #----------------------------------------------------------------
179 # Jar file recursive Class-Path reference is OK
180 #----------------------------------------------------------------
181 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -classpath classesRefRef.jar Main.java
182 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -Xbootclasspath/p:classesRefRef.jar Main.java
184 #----------------------------------------------------------------
185 # Class-Path attribute ignored in extdirs or endorseddirs
186 #----------------------------------------------------------------
187 Sys mkdir jars
188 Sys cp -p classesRefRef.jar jars/.
189 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -extdirs jars Main.java
190 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -endorseddirs jars Main.java
192 #----------------------------------------------------------------
193 # Bad Jar file in extdirs and endorseddirs should not be ignored
194 #----------------------------------------------------------------
195 BadJarFile jars/classesRef.jar
196 Error "$javac" ${TESTTOOLVMOPTS} -Xlint -extdirs jars Main.java
197 Error "$javac" ${TESTTOOLVMOPTS} -Xlint -endorseddirs jars Main.java
199 Cleanup
201 Bottom Line