Mon, 13 Feb 2012 16:01:43 -0800
7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Sun Feb 12 16:44:13 2012 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Mon Feb 13 16:01:43 2012 -0800 1.3 @@ -1077,7 +1077,9 @@ 1.4 boolean errors = false; 1.5 for (String nameStr : classnames) { 1.6 Symbol sym = resolveBinaryNameOrIdent(nameStr); 1.7 - if (sym == null || (sym.kind == Kinds.PCK && !processPcks)) { 1.8 + if (sym == null || 1.9 + (sym.kind == Kinds.PCK && !processPcks) || 1.10 + sym.kind == Kinds.ABSENT_TYP) { 1.11 log.error("proc.cant.find.class", nameStr); 1.12 errors = true; 1.13 continue;
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/T7142672/AnnoProcessor.java Mon Feb 13 16:01:43 2012 -0800 2.3 @@ -0,0 +1,44 @@ 2.4 +/* 2.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +import java.util.Set; 2.28 +import javax.annotation.processing.*; 2.29 +import javax.lang.model.SourceVersion; 2.30 +import javax.lang.model.element.TypeElement; 2.31 + 2.32 +@SupportedAnnotationTypes("Anno") 2.33 +public class AnnoProcessor extends AbstractProcessor { 2.34 + @Override 2.35 + public SourceVersion getSupportedSourceVersion() { 2.36 + return SourceVersion.latest(); 2.37 + } 2.38 + 2.39 + @Override 2.40 + public boolean process(Set<? extends TypeElement> set, RoundEnvironment re) { 2.41 + System.out.println("RUNNING..."); 2.42 + if(set.isEmpty()) { 2.43 + return false; 2.44 + } 2.45 + return false; 2.46 + } 2.47 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/T7142672/Bug.java Mon Feb 13 16:01:43 2012 -0800 3.3 @@ -0,0 +1,85 @@ 3.4 +/* 3.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test 3.29 + * @bug 7142672 3.30 + * @summary Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...) 3.31 + * @author holmlund 3.32 + * @compile AnnoProcessor.java Bug.java Test3.java 3.33 + * @run main Bug Test2.java 3.34 + * @run main Bug Test2.foo 3.35 + * @run main Bug Test3.java 3.36 + */ 3.37 +import java.io.*; 3.38 +import java.util.*; 3.39 +import javax.tools.*; 3.40 + 3.41 +// Each run should output the 'could not find class file' message, and not throw an AssertError. 3.42 +public class Bug { 3.43 + public static void main(String... arg) throws Throwable { 3.44 + String name = arg[0]; 3.45 + final String expectedMsg = "error: Could not find class file for '" + name + "'."; 3.46 + JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); 3.47 + JavaCompiler.CompilationTask task2; 3.48 + StringWriter sw = new StringWriter(); 3.49 + final PrintWriter pw = new PrintWriter(sw); 3.50 + 3.51 + 3.52 + DiagnosticListener<? super javax.tools.JavaFileObject> dl = 3.53 + new DiagnosticListener<javax.tools.JavaFileObject>() { 3.54 + public void report(Diagnostic message) { 3.55 + pw.print("Diagnostic:\n"+ message.toString()+"\n"); 3.56 + if (!message.toString().equals(expectedMsg)){ 3.57 + System.err.println("Diagnostic:\n"+ message.toString()+"\n"); 3.58 + System.err.println("--Failed: Unexpected diagnostic"); 3.59 + System.exit(1); 3.60 + } 3.61 + } 3.62 + }; 3.63 + 3.64 + StandardJavaFileManager sjfm = javac.getStandardFileManager(dl,null,null); 3.65 + 3.66 + List<String> opts = new ArrayList<String>(); 3.67 + opts.add("-proc:only"); 3.68 + opts.add("-processor"); 3.69 + opts.add("AnnoProcessor"); 3.70 + 3.71 + boolean xxx; 3.72 + 3.73 + System.err.println("\n-- " + name); 3.74 + task2 = javac.getTask(pw, sjfm, dl, opts, Arrays.asList(name), null); 3.75 + xxx = task2.call(); 3.76 + 3.77 + String out = sw.toString(); 3.78 + System.err.println(out); 3.79 + if (out.contains("Assert")) { 3.80 + System.err.println("--Failed: Assertion failure"); 3.81 + System.exit(1); 3.82 + } 3.83 + if (!out.contains(expectedMsg)) { 3.84 + System.err.println("--Failed: Expected diagnostic not found"); 3.85 + System.exit(1); 3.86 + } 3.87 + } 3.88 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/T7142672/Test2.java Mon Feb 13 16:01:43 2012 -0800 4.3 @@ -0,0 +1,25 @@ 4.4 +/* 4.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +class Test2 { 4.28 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javac/T7142672/Test3.java Mon Feb 13 16:01:43 2012 -0800 5.3 @@ -0,0 +1,25 @@ 5.4 +/* 5.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + */ 5.26 + 5.27 +class Test3 { 5.28 +}