test/langtools/tools/javac/classreader/FileSystemClosedTest.java
author yzheng
Wed, 16 Oct 2019 16:54:56 +0200
changeset 58650 d068b1e534de
parent 47216 71c04702a3d5
permissions -rw-r--r--
8231754: [JVMCI] Make r27 unconditionally reserved in JVMCI Summary: Reserve r27 (heap base register) on AArch64 unconditionally Reviewed-by: adinn, dlong
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43268
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
     1
/*
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
     4
 *
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
     8
 *
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    13
 * accompanied this code).
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    14
 *
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    18
 *
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    21
 * questions.
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    22
 */
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    23
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    24
/*
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    25
 * @test
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    26
 * @bug 8147414
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    27
 * @summary java.nio.file.ClosedFileSystemException in javadoc
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    28
 * @library /tools/lib
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    31
 * @build toolbox.JarTask toolbox.JavacTask toolbox.ToolBox
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    32
 * @run main FileSystemClosedTest
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    33
 */
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    34
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    35
import java.io.IOException;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    36
import java.io.PrintWriter;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    37
import java.nio.file.ClosedFileSystemException;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    38
import java.nio.file.Files;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    39
import java.nio.file.Path;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    40
import java.nio.file.Paths;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    41
import java.util.Arrays;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    42
import java.util.List;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    43
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    44
import javax.lang.model.element.PackageElement;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    45
import javax.lang.model.element.TypeElement;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    46
import javax.lang.model.util.Elements;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    47
import javax.tools.JavaCompiler;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    48
import javax.tools.JavaFileObject;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    49
import javax.tools.StandardJavaFileManager;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    50
import javax.tools.ToolProvider;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    51
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    52
import toolbox.ToolBox;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    53
import toolbox.JarTask;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    54
import toolbox.JavacTask;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    55
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    56
public class FileSystemClosedTest {
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    57
    public static void main(String... args) throws Exception {
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    58
        new FileSystemClosedTest().run();
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    59
    }
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    60
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    61
    void run() throws Exception {
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    62
        ToolBox tb = new ToolBox();
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    63
        Path jar = createJar(tb);
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    64
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    65
        Path src = Paths.get("src");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    66
        tb.writeJavaFiles(src, "class C { p1.C1 c1; }");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    67
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    68
        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    69
        PrintWriter out = new PrintWriter(System.err, true);
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    70
        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
43277
edf2836a33f7 8173141: tools/javac/classreader/FileSystemClosedTest.java fails on Windows
jjg
parents: 43268
diff changeset
    71
        List<String> options = Arrays.asList("-classpath", jar.toString(), "-proc:none");
43268
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    72
        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(src.resolve("C.java"));
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    73
        com.sun.source.util.JavacTask task =
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    74
                (com.sun.source.util.JavacTask) comp.getTask(out, fm, null, options, null, files);
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    75
        task.parse();
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    76
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    77
        Elements elems = task.getElements();
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    78
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    79
        try {
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    80
            // Use  p1, p1.C1 as a control to verify normal behavior
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    81
            PackageElement p1 = elems.getPackageElement("p1");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    82
            TypeElement p1C1 = elems.getTypeElement("p1.C1");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    83
            System.err.println("p1: " + p1 + ";  p1C1: " + p1C1);
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    84
            if (p1C1 == null) {
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    85
                throw new Exception("p1.C1 not found");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    86
            }
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    87
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    88
            // Now repeat for p2, p2.C2, closing the file manager early
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    89
            PackageElement p2 = elems.getPackageElement("p2");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    90
            System.err.println("closing file manager");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    91
            fm.close();
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    92
            TypeElement p2C2 = elems.getTypeElement("p2.C2");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    93
            System.err.println("p2: " + p2 + ";  p2C2: " + p2C2);
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    94
            if (p2C2 != null) {
43277
edf2836a33f7 8173141: tools/javac/classreader/FileSystemClosedTest.java fails on Windows
jjg
parents: 43268
diff changeset
    95
                throw new Exception("p2.C2 found unexpectedly");
43268
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    96
            }
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    97
        } catch (ClosedFileSystemException e) {
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    98
            throw new Exception("unexpected exception thrown", e);
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
    99
        }
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   100
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   101
    }
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   102
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   103
    private Path createJar(ToolBox tb) throws IOException {
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   104
        Path jarSrc = Paths.get("jarSrc");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   105
        Path jarClasses = Paths.get("jarClasses");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   106
        Path jar = Paths.get("jar.jar");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   107
        Files.createDirectories(jarClasses);
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   108
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   109
        tb.writeJavaFiles(jarSrc,
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   110
                "package p1; public class C1 { }",
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   111
                "package p2; public class C2 { }");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   112
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   113
        new JavacTask(tb)
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   114
                .outdir(jarClasses)
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   115
                .files(tb.findJavaFiles(jarSrc))
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   116
                .run()
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   117
                .writeAll();
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   118
        new JarTask(tb)
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   119
                .run("cf", jar.toString(), "-C", jarClasses.toString(), "p1", "p2");
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   120
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   121
        return jar;
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   122
    }
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   123
}
12436ebea906 8147414: java.nio.file.ClosedFileSystemException in javadoc
jjg
parents:
diff changeset
   124