test/tools/javac/processing/6348499/T6348499.java

Mon, 20 Aug 2012 13:50:04 -0700

author
jjg
date
Mon, 20 Aug 2012 13:50:04 -0700
changeset 1308
37008b4cd97a
parent 699
d2aaaec153e8
child 1466
b52a38d4536c
permissions
-rw-r--r--

7192744: fix up tests to accommodate jtreg spec change
Reviewed-by: darcy

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

mercurial