langtools/test/tools/javac/T7142672/Bug.java
author jjg
Wed, 29 Oct 2014 17:25:23 -0700
changeset 27319 030080f03e4f
parent 11867 1fa9d18707da
child 30730 d3ce7619db2c
permissions -rw-r--r--
8062348: langtools tests should close file manager (group 1) Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11867
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
     1
/*
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
     2
 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
11867
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
     4
 *
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
     8
 *
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    13
 * accompanied this code).
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    14
 *
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    18
 *
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    21
 * questions.
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    22
 */
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    23
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    24
/*
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    25
 * @test
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    26
 * @bug 7142672
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    27
 * @summary Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    28
 * @author holmlund
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    29
 * @compile AnnoProcessor.java Bug.java Test3.java
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    30
 * @run main Bug Test2.java
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    31
 * @run main Bug Test2.foo
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    32
 * @run main Bug Test3.java
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    33
 */
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    34
import java.io.*;
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    35
import java.util.*;
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    36
import javax.tools.*;
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    37
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    38
// Each run should output the 'could not find class file' message, and not throw an AssertError.
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    39
public class Bug {
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    40
    public static void main(String... arg) throws Throwable {
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    41
        String name = arg[0];
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    42
        final String expectedMsg = "error: Could not find class file for '" + name + "'.";
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    43
        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    44
        JavaCompiler.CompilationTask task2;
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    45
        StringWriter sw = new StringWriter();
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    46
        final PrintWriter pw = new PrintWriter(sw);
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    47
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    48
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    49
        DiagnosticListener<? super javax.tools.JavaFileObject> dl =
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    50
            new DiagnosticListener<javax.tools.JavaFileObject>() {
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    51
            public void report(Diagnostic message) {
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    52
                pw.print("Diagnostic:\n"+ message.toString()+"\n");
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    53
                if (!message.toString().equals(expectedMsg)){
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    54
                    System.err.println("Diagnostic:\n"+ message.toString()+"\n");
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    55
                    System.err.println("--Failed: Unexpected diagnostic");
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    56
                    System.exit(1);
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    57
                }
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    58
            }
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    59
        };
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    60
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    61
        try (StandardJavaFileManager sjfm = javac.getStandardFileManager(dl,null,null)) {
11867
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    62
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    63
            List<String> opts = new ArrayList<String>();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    64
            opts.add("-proc:only");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    65
            opts.add("-processor");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    66
            opts.add("AnnoProcessor");
11867
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    67
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    68
            boolean xxx;
11867
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    69
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    70
            System.err.println("\n-- " + name);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    71
            task2 = javac.getTask(pw, sjfm, dl, opts, Arrays.asList(name), null);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    72
            xxx = task2.call();
11867
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    73
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    74
            String out = sw.toString();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    75
            System.err.println(out);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    76
            if (out.contains("Assert")) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    77
                System.err.println("--Failed: Assertion failure");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    78
                System.exit(1);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    79
            }
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    80
            if (!out.contains(expectedMsg)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    81
                System.err.println("--Failed: Expected diagnostic not found");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    82
                System.exit(1);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 11867
diff changeset
    83
            }
11867
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    84
        }
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    85
    }
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
diff changeset
    86
}