Sat, 01 Dec 2007 00:00:00 +0000
Initial load
1 /*
2 * Copyright 2006 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
24 /*
25 * @test
26 * @bug 6441871
27 * @summary javac crashes at com.sun.tools.javac.jvm.ClassReader$BadClassFile
28 * @build A
29 * @run main T6348499
30 */
32 // Note that 6441871 is an interim partial fix for 6348499 that just removes the javac
33 // crash message and stacktrace
35 import java.io.*;
36 import java.util.*;
37 import javax.annotation.processing.*;
38 import javax.lang.model.*;
39 import javax.lang.model.element.*;
40 import javax.tools.*;
41 import com.sun.source.util.*;
42 import com.sun.tools.javac.api.*;
45 public class T6348499 {
46 public static void main(String... args) {
47 String testSrc = System.getProperty("test.src", ".");
48 String testClasses = System.getProperty("test.classes");
49 String A_java = new File(testSrc, "A.java").getPath();
50 JavacTool tool = JavacTool.create();
51 MyDiagListener dl = new MyDiagListener();
52 StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
53 Iterable<? extends JavaFileObject> files =
54 fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java")));
55 Iterable<String> opts = Arrays.asList("-proc:only",
56 "-processor", "A",
57 "-processorpath", testClasses);
58 StringWriter out = new StringWriter();
59 JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
60 task.call();
61 String s = out.toString();
62 System.err.print(s);
63 // Expect the following 1 multi-line diagnostic, and no output to log
64 // error: cannot access A_0
65 // bad class file: A_0.class
66 // illegal start of class file
67 // Please remove or make sure it appears in the correct subdirectory of the classpath.
68 System.err.println(dl.count + " diagnostics; " + s.length() + " characters");
69 if (dl.count != 1 || s.length() != 0)
70 throw new AssertionError("unexpected output from compiler");
71 }
73 static class MyDiagListener implements DiagnosticListener<JavaFileObject> {
74 public void report(Diagnostic d) {
75 System.err.println(d);
76 count++;
77 }
79 public int count;
80 }
82 private static String self = T6348499.class.getName();
83 }