Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/CheckEndorsedAndExtDirs/EndorsedExtDirs.java
32284 views
/*1* Copyright (c) 2014, 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 806466726* @summary Sanity test for -XX:+CheckEndorsedAndExtDirs27* @library /testlibrary28* @build com.oracle.java.testlibrary.*29* @run main/othervm EndorsedExtDirs30*/3132import com.oracle.java.testlibrary.*;33import java.io.File;34import java.io.IOException;35import java.nio.file.attribute.BasicFileAttributes;36import java.nio.file.Files;37import java.nio.file.Path;38import java.nio.file.Paths;39import java.util.ArrayList;40import java.util.List;4142public class EndorsedExtDirs {43static final String cpath = System.getProperty("test.classes", ".");44public static void main(String arg[]) throws Exception {45fatalError("-XX:+CheckEndorsedAndExtDirs", "-Djava.endorsed.dirs=foo");46fatalError("-XX:+CheckEndorsedAndExtDirs", "-Djava.ext.dirs=bar");47testNonEmptySystemExtDirs();48}4950static void testNonEmptySystemExtDirs() throws Exception {51String home = System.getProperty("java.home");52Path ext = Paths.get(home, "lib", "ext");53String extDirs = System.getProperty("java.ext.dirs");54String[] dirs = extDirs.split(File.pathSeparator);55long count = 0;56for (String d : dirs) {57Path path = Paths.get(d);58if (Files.notExists(path) || path.equals(ext)) continue;59count += Files.find(path, 1, (Path p, BasicFileAttributes attr)60-> p.getFileName().toString().endsWith(".jar"))61.count();62}63if (count > 0) {64fatalError("-XX:+CheckEndorsedAndExtDirs");65}66}6768static ProcessBuilder newProcessBuilder(String... args) {69List<String> commands = new ArrayList<>();70String java = System.getProperty("java.home") + "/bin/java";71commands.add(java);72for (String s : args) {73commands.add(s);74}75commands.add("-cp");76commands.add(cpath);77commands.add("EndorsedExtDirs");7879System.out.println("Process " + commands);80return new ProcessBuilder(commands);81}8283static void fatalError(String... args) throws Exception {84fatalError(newProcessBuilder(args));85}8687static void fatalError(ProcessBuilder pb) throws Exception {88OutputAnalyzer output = new OutputAnalyzer(pb.start());89output.shouldContain("Could not create the Java Virtual Machine");90output.shouldHaveExitValue(1);91}92}939495