Path: blob/master/test/functional/cmdLineTests/proxyFieldAccess/src/defect/cmvc198986/TestProxyFieldAccess.java
6007 views
/*******************************************************************************1* Copyright (c) 2001, 2018 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21package defect.cmvc198986;2223import java.io.File;24import java.lang.ClassLoader;25import java.lang.reflect.Method;26import java.net.MalformedURLException;27import java.net.URL;28import java.net.URLClassLoader;29import java.util.ArrayList;3031public class TestProxyFieldAccess {3233public static void main(String[] args) {34new TestProxyFieldAccess().test();35}3637void test() {38try {39MyClassLoader mcl3 = new MyClassLoader(getClassPathURLs(getClass().getClassLoader()));4041Class<?> cls = mcl3.loadClass("defect.cmvc198986.ProxyFieldAccess");42Method m = cls.getDeclaredMethod("main", String[].class);43m.invoke(cls, new Object[] { new String[0] });4445} catch (Exception e) {46// TODO Auto-generated catch block47e.printStackTrace();48}49}5051private static URL[] getClassPathURLs(ClassLoader classLoader) {52if (classLoader instanceof URLClassLoader) {53return ((URLClassLoader)classLoader).getURLs();54}5556/* Parse the java.class.path env var */57String classpath = System.getProperty("java.class.path");58String[] paths = classpath.split(File.pathSeparator);59if (paths.length == 0) {60return new URL[0];61}6263ArrayList<URL> urls = new ArrayList<URL>(paths.length);64for (String path : paths) {65try {66urls.add(new File(path).toURI().toURL());67} catch (MalformedURLException e) {68e.printStackTrace();69}70}71return urls.toArray(new URL[0]);72}7374}757677