langtools/test/tools/javac/T6900149.java
author lana
Thu, 21 Jan 2016 09:46:01 -0800
changeset 35340 38f7386ed942
parent 30730 d3ce7619db2c
permissions -rw-r--r--
Added tag jdk-9+102 for changeset 7e3feb2ba5b3
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
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
     2
 * Copyright (c) 2010, 2015, 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
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    28
 * @modules java.compiler
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    29
 *          jdk.compiler
6596
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    30
 */
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    31
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    32
import java.io.*;
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    33
import java.util.*;
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    34
import javax.tools.*;
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    35
import javax.tools.JavaCompiler.CompilationTask;
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    36
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    37
public class T6900149 {
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    38
    public static void main(String[] args) throws IOException {
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    39
        DiagnosticCollector<JavaFileObject> diag =
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    40
                new DiagnosticCollector<JavaFileObject>();
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    41
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    42
        try (StandardJavaFileManager fm =
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    43
                compiler.getStandardFileManager(null, null, null)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    44
            File emptyFile = createTempFile("Empty.java");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    45
            File[] files = new File[] { emptyFile, emptyFile };
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    46
            CompilationTask task = compiler.getTask(null, fm, diag,
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    47
                    null, null, fm.getJavaFileObjects(files));
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    48
            if (! task.call()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    49
                throw new AssertionError("compilation failed");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 16800
diff changeset
    50
            }
6596
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    51
        }
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    52
    }
16800
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    53
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    54
    private static File createTempFile(String path) throws IOException {
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    55
        File f = new File(path);
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    56
        try (FileWriter out = new FileWriter(f)) { }
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    57
        return f;
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    58
    }
6596
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    59
}