T6430209.java revision 698:d2aaaec153e8
1/* 2 * Copyright (c) 2006, 2010, 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 6441871 27 * @summary spurious compiler error elicited by packageElement.getEnclosedElements() 28 * @library ../../lib 29 * @build JavacTestingAbstractProcessor b6341534 30 * @run main T6430209 31 */ 32 33// Note that 6441871 is an interim partial fix for 6430209 that just removes the javac 34// crash message and stacktrace 35 36import java.io.*; 37import java.util.*; 38import javax.annotation.processing.*; 39import javax.lang.model.*; 40import javax.lang.model.element.*; 41import javax.tools.*; 42import com.sun.source.util.*; 43import com.sun.tools.javac.api.*; 44 45 46public class T6430209 { 47 public static void main(String... args) throws IOException { 48 // set up dir1/test0.java 49 File dir1 = new File("dir1"); 50 dir1.mkdir(); 51 BufferedWriter fout = new BufferedWriter(new FileWriter(new File(dir1, "test0.java"))); 52 fout.write("public class test0 { }"); 53 fout.close(); 54 55 // run annotation processor b6341534 so we can check diagnostics 56 // -proc:only -processor b6341534 -cp . ./src/*.java 57 String testSrc = System.getProperty("test.src", "."); 58 String testClasses = System.getProperty("test.classes") + System.getProperty("path.separator") + "../../lib"; 59 JavacTool tool = JavacTool.create(); 60 MyDiagListener dl = new MyDiagListener(); 61 StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null); 62 fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(new File("."))); 63 Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList( 64 new File(testSrc, "test0.java"), new File(testSrc, "test1.java"))); 65 Iterable<String> opts = Arrays.asList("-proc:only", 66 "-processor", "b6341534", 67 "-processorpath", testClasses); 68 StringWriter out = new StringWriter(); 69 JavacTask task = tool.getTask(out, fm, dl, opts, null, files); 70 task.call(); 71 String s = out.toString(); 72 System.err.print(s); 73 // Expect the following 2 diagnostics, and no output to log 74 System.err.println(dl.count + " diagnostics; " + s.length() + " characters"); 75 if (dl.count != 2 || s.length() != 0) 76 throw new AssertionError("unexpected output from compiler"); 77 } 78 79 static class MyDiagListener implements DiagnosticListener<JavaFileObject> { 80 public void report(Diagnostic d) { 81 System.err.println(d); 82 count++; 83 } 84 85 public int count; 86 } 87} 88