1 /* 2 * Copyright (c) 2014, 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 8067951 27 * @summary Unit test for internal ClassLoader#initializePath(). 28 * Quoted entries should get unquoted. 29 * Empty entries should be replaced with dot. 30 * @run main LibraryPathProperty 31 */ 32 33 import java.lang.reflect.Method; 34 import java.io.File; 35 import java.util.Arrays; 36 37 public class LibraryPathProperty { 38 39 static final String propName = "test.property.name"; 40 static final String SP = File.pathSeparator; 41 static Method method; 42 43 public static void main(String[] args) throws Throwable { 44 method = ClassLoader.class 45 .getDeclaredMethod("initializePath", 46 String.class); 47 method.setAccessible(true); 48 49 test("", "."); 50 test("\"\"", "."); 51 test(SP, ".", "."); 52 test("\"\"" + SP, ".", "."); 53 test(SP + "\"\"", ".", "."); 54 test("a" + SP, "a", "."); 55 test(SP + "b", ".", "b"); 56 test("a" + SP + SP + "b", "a", ".", "b"); 57 test("a" + SP + "\"b\"" + SP, "a", "b", "."); 58 test(SP + "a" + SP + SP + "\"b\"", ".", "a", ".", "b"); 59 test("\"a\"" + SP + "\"b\"", "a", "b"); 60 61 // some not yet supported variants of paths 62 //test("\"/a/\"b" + SP + "c", "/a/b", "c"); // partially quoted path 63 //test("\"/a;b\"" + SP + "c", "/a;b", "c"); // quoted path with semicolon 64 //test("\"/a:b\"" + SP + "c", "/a:b", "c"); // quoted path with colon 65 //test("\"/a\\\"b\"" + SP + "c", "/a\"b", "c"); // escaped quote 66 } 67 68 static void test(String s, String... expected) throws Throwable { 69 System.setProperty(propName, s); 70 String[] res = (String[])method.invoke(null, propName); 71 if (!Arrays.asList(res).equals(Arrays.asList(expected))) { 72 throw new RuntimeException("Parsing [" + s + "] " + 73 " result " + Arrays.asList(res) + 74 " doesn't match " + Arrays.asList(expected)); 75 } 76 } 77 }