Path: blob/master/test/jdk/java/lang/ClassLoader/EndorsedDirs.java
41152 views
/*1* Copyright (c) 2014, 2018, 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 8060206 806736626* @library /test/lib27* @summary Endorsed standards and override mechanism is removed28*/2930import jdk.test.lib.process.ProcessTools;3132import java.util.stream.Stream;3334public class EndorsedDirs {35private static String TEST_CLASSES = System.getProperty("test.classes", ".");3637private static String[] VALUES = new String[] {38null,39"",40"\"\""41};4243public static void main(String... args) throws Exception {44String value = System.getProperty("java.endorsed.dirs");45System.out.format("java.endorsed.dirs = '%s'%n", value);46if (args.length > 0) {47int index = Integer.valueOf(args[0]);48String expectedValue = VALUES[index];49if (!(expectedValue == value ||50(value != null && value.isEmpty()) ||51(expectedValue != null & expectedValue.equals(value)))) {52throw new RuntimeException("java.endorsed.dirs (" +53value + ") != " + expectedValue);54}55// launched by subprocess.56return;57}5859if (value != null) {60throw new RuntimeException("java.endorsed.dirs not removed: " + value);61}6263fatalError(0, "-Djava.endorsed.dirs=foo");64start(0);65start(1, "-Djava.endorsed.dirs=");66start(2, "-Djava.endorsed.dirs=\"\"");67}6869static String[] launchOptions(int testParam, String... args) {70return Stream.concat(Stream.of(args),71Stream.of("-cp", TEST_CLASSES, "EndorsedDirs",72String.valueOf(testParam)))73.toArray(String[]::new);74}7576static void start(int testParam, String... args) throws Exception {77ProcessTools.executeTestJava(launchOptions(testParam, args))78.shouldHaveExitValue(0);79}8081static void fatalError(int testParam, String... args) throws Exception {82ProcessTools.executeTestJava(launchOptions(testParam, args))83.stderrShouldContain("Could not create the Java Virtual Machine");84}85}868788