langtools/test/tools/javac/T6900149.java
author katleman
Thu, 21 Aug 2014 14:16:14 -0700
changeset 25878 6d561031123e
parent 16800 3267051107a1
child 27319 030080f03e4f
permissions -rw-r--r--
Added tag jdk9-b27 for changeset 98ce0879ab4c
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
/*
16800
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
     2
 * Copyright (c) 2010, 2013, 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();
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    40
        StandardJavaFileManager fm =
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    41
                compiler.getStandardFileManager(null, null, null);
16800
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    42
        File emptyFile = createTempFile("Empty.java");
6596
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    43
        File[] files = new File[] { emptyFile, emptyFile };
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    44
        CompilationTask task = compiler.getTask(null, fm, diag,
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    45
                null, null, fm.getJavaFileObjects(files));
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    46
        if (! task.call()) {
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    47
            throw new AssertionError("compilation failed");
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    48
        }
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    49
    }
16800
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    50
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    51
    private static File createTempFile(String path) throws IOException {
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    52
        File f = new File(path);
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    53
        try (FileWriter out = new FileWriter(f)) { }
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    54
        return f;
3267051107a1 8010511: Tests are creating files in /tmp
jjg
parents: 6596
diff changeset
    55
    }
6596
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
diff changeset
    56
}