1 /* 2 * Copyright (c) 2016, 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 import com.sun.jdi.connect.*; 25 import com.sun.jdi.*; 26 import java.util.Map; 27 import java.util.List; 28 import jdk.test.lib.Asserts; 29 30 /* 31 * @test 32 * @summary Verifies that PathSearchingVirtualMachine.bootClassPath() 33 * returns an empty list in case no bootclass path specified 34 * regardless of sun.boot.class.path option, which is now obsolete 35 * @library /test/lib 36 * @compile TestClass.java 37 * @compile SunBootClassPathEmptyTest.java 38 * @run main/othervm SunBootClassPathEmptyTest 39 */ 40 public class SunBootClassPathEmptyTest { 41 42 /** 43 * Helper class to facilitate the debuggee VM launching 44 */ 45 private static class VmConnector { 46 47 LaunchingConnector lc; 48 VirtualMachine vm; 49 50 VmConnector() { 51 for (LaunchingConnector c : Bootstrap.virtualMachineManager().launchingConnectors()) { 52 System.out.println("name: " + c.name()); 53 if (c.name().equals("com.sun.jdi.CommandLineLaunch")) { 54 lc = c; 55 break; 56 } 57 } 58 if (lc == null) { 59 throw new RuntimeException("Connector not found"); 60 } 61 } 62 63 PathSearchingVirtualMachine launchVm(String cmdLine, String options) throws Exception { 64 Map<String, Connector.Argument> vmArgs = lc.defaultArguments(); 65 vmArgs.get("main").setValue(cmdLine); 66 if (options != null) { 67 vmArgs.get("options").setValue(options); 68 } 69 System.out.println("Debugger is launching vm ..."); 70 vm = lc.launch(vmArgs); 71 if (!(vm instanceof PathSearchingVirtualMachine)) { 72 throw new RuntimeException("VM is not a PathSearchingVirtualMachine"); 73 } 74 return (PathSearchingVirtualMachine) vm; 75 } 76 77 } 78 79 private static VmConnector connector = new VmConnector(); 80 81 public static void main(String[] args) throws Exception { 82 testWithObsoleteClassPathOption(null); 83 testWithObsoleteClassPathOption("someclasspath"); 84 } 85 86 private static void testWithObsoleteClassPathOption(String obsoleteClassPath) throws Exception { 87 PathSearchingVirtualMachine vm = connector.launchVm("TestClass", makeClassPathOptions(obsoleteClassPath)); 88 List<String> bootClassPath = vm.bootClassPath(); 89 Asserts.assertNotNull(bootClassPath, "Expected bootClassPath to be empty but was null"); 90 Asserts.assertEquals(0, bootClassPath.size(), "Expected bootClassPath.size() 0 but was: " + bootClassPath.size()); 91 } 92 93 private static String makeClassPathOptions(String obsoleteClassPath) { 94 return obsoleteClassPath == null ? null : "-Dsun.boot.class.path=" + obsoleteClassPath; 95 } 96 97 }