langtools/test/tools/javac/T6900149.java
author jjg
Wed, 29 Oct 2014 17:25:23 -0700
changeset 27319 030080f03e4f
parent 16800 3267051107a1
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:
6596
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
     1
/*
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
     2
 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
6596
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
     4
 *
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
     8
 *
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    13
 * accompanied this code).
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    14
 *
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    18
 *
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    21
 * questions.
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    22
 */
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    23
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    24
/*
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    25
 * @test
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    26
 * @bug 6900149
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    27
 * @summary IllegalStateException when compiling same files and DiagnosticListener is set
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    28
 */
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    29
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    30
import java.io.*;
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    31
import java.util.*;
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    32
import javax.tools.*;
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    33
import javax.tools.JavaCompiler.CompilationTask;
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    34
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    35
public class T6900149 {
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    36
    public static void main(String[] args) throws IOException {
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    37
        DiagnosticCollector<JavaFileObject> diag =
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    38
                new DiagnosticCollector<JavaFileObject>();
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    39
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    40
        try (StandardJavaFileManager fm =
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    41
                compiler.getStandardFileManager(null, null, null)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    42
            File emptyFile = createTempFile("Empty.java");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    43
            File[] files = new File[] { emptyFile, emptyFile };
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    44
            CompilationTask task = compiler.getTask(null, fm, diag,
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    45
                    null, null, fm.getJavaFileObjects(files));
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    46
            if (! task.call()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    47
                throw new AssertionError("compilation failed");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    48
            }
6596
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    49
        }
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    50
    }
16800
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    51
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    52
    private static File createTempFile(String path) throws IOException {
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    53
        File f = new File(path);
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    54
        try (FileWriter out = new FileWriter(f)) { }
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    55
        return f;
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    56
    }
6596
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    57
}