Path: blob/master/test/jdk/java/io/FilePermission/ReadFileOnPath.java
41149 views
/*1* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 816470526* @library /test/lib27* @modules java.base/jdk.internal.misc28* jdk.compiler29* @build jdk.test.lib.compiler.CompilerUtils30* jdk.test.lib.Utils31* jdk.test.lib.Asserts32* jdk.test.lib.JDKToolFinder33* jdk.test.lib.JDKToolLauncher34* jdk.test.lib.Platform35* jdk.test.lib.process.*36* jdk.test.lib.util.JarUtils37* @run main ReadFileOnPath38* @summary Still able to read file on the same path39*/4041import jdk.test.lib.process.ProcessTools;42import jdk.test.lib.compiler.CompilerUtils;43import jdk.test.lib.util.JarUtils;4445import java.nio.file.Files;46import java.nio.file.Path;47import java.nio.file.Paths;48import java.util.ArrayList;49import java.util.Arrays;50import java.util.List;5152public class ReadFileOnPath {5354private static final Path SRC_DIR = Paths.get(System.getProperty("test.src"));55private static final Path HERE_DIR = Paths.get(".");56private static final Path MODS_DIR = Paths.get("modules");5758public static void main(String args[]) throws Exception {59CompilerUtils.compile(SRC_DIR.resolve("m"), MODS_DIR.resolve("m"));60Files.write(MODS_DIR.resolve("m/base"), "base".getBytes());61Files.write(MODS_DIR.resolve("m/p/child"), "child".getBytes());62JarUtils.createJarFile(HERE_DIR.resolve("old.jar"),63MODS_DIR.resolve("m"),64"base", "p/App.class", "p/child");65JarUtils.createJarFile(HERE_DIR.resolve("new.jar"),66MODS_DIR.resolve("m"),67"module-info.class", "base", "p/App.class", "p/child");6869// exploded module70test("--module-path", "modules", "-m", "m/p.App", "SS++++0");7172// module in jar73test("--module-path", "new.jar", "-m", "m/p.App", "SSSS++0");7475// exploded classpath76test("-cp", "modules/m", "p.App", "SS+++++");7778// classpath in jar79test("-cp", "old.jar", "p.App", "SSSS++0");80}8182static void test(String... args) throws Exception {83List<String> cmds = new ArrayList<>();84cmds.add("-Djava.security.manager");85cmds.addAll(Arrays.asList(args));86cmds.addAll(List.of(87"x", "modules/m", "modules/m/base", "modules/m/p/child",88"-", "child", "/base", "../base"));89ProcessTools.executeTestJvm(cmds.toArray(new String[cmds.size()]))90.shouldHaveExitValue(0);91}92}939495