1 /*
2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @bug 8060206 8067366
27  * @library /test/lib
28  * @summary Endorsed standards and override mechanism is removed
29  */
30 
31 import jdk.test.lib.process.ProcessTools;
32 
33 import java.util.stream.Stream;
34 
35 public class EndorsedDirs {
36     private static String TEST_CLASSES = System.getProperty("test.classes", ".");
37 
38     private static String[] VALUES = new String[] {
39             null,
40             "",
41             "\"\""
42     };
43 
main(String... args)44     public static void main(String... args) throws Exception {
45         String value = System.getProperty("java.endorsed.dirs");
46         System.out.format("java.endorsed.dirs = '%s'%n", value);
47         if (args.length > 0) {
48             int index = Integer.valueOf(args[0]);
49             String expectedValue = VALUES[index];
50             if (!(expectedValue == value ||
51                     (value != null && value.isEmpty()) ||
52                     (expectedValue != null & expectedValue.equals(value)))) {
53                 throw new RuntimeException("java.endorsed.dirs (" +
54                         value + ") != " + expectedValue);
55             }
56             // launched by subprocess.
57             return;
58         }
59 
60         if (value != null) {
61             throw new RuntimeException("java.endorsed.dirs not removed: " + value);
62         }
63 
64         fatalError(0, "-Djava.endorsed.dirs=foo");
65         start(0);
66         start(1, "-Djava.endorsed.dirs=");
67         start(2, "-Djava.endorsed.dirs=\"\"");
68     }
69 
launchOptions(int testParam, String... args)70     static String[] launchOptions(int testParam, String... args) {
71         return Stream.concat(Stream.of(args),
72                              Stream.of("-cp", TEST_CLASSES, "EndorsedDirs",
73                                        String.valueOf(testParam)))
74                      .toArray(String[]::new);
75     }
76 
start(int testParam, String... args)77     static void start(int testParam, String... args) throws Exception {
78         ProcessTools.executeTestJava(launchOptions(testParam, args))
79                     .shouldHaveExitValue(0);
80     }
81 
fatalError(int testParam, String... args)82     static void fatalError(int testParam, String... args) throws Exception {
83         ProcessTools.executeTestJava(launchOptions(testParam, args))
84                     .stderrShouldContain("Could not create the Java Virtual Machine");
85     }
86 }
87