undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4112682
|
||||
* @summary RMIClassLoader's loadClass() method that takes explicit URLs
|
||||
* should load classes from a class loader that delegates to the current
|
||||
* thread's context class loader (not just the base class loader always).
|
||||
* @author Peter Jones
|
||||
*
|
||||
* @library ../../../testlibrary
|
||||
* @modules java.rmi/sun.rmi.registry
|
||||
* java.rmi/sun.rmi.server
|
||||
* java.rmi/sun.rmi.transport
|
||||
* java.rmi/sun.rmi.transport.tcp
|
||||
* @build TestLibrary Dummy
|
||||
* @run main/othervm/timeout=120 DelegateToContextLoader
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.rmi.server.RMIClassLoader;
|
||||
|
||||
public class DelegateToContextLoader {
|
||||
|
||||
/** name of target class to attempt to load */
|
||||
private static final String className = "Dummy";
|
||||
|
||||
/** name of file containing definition for target class */
|
||||
private static final String classFileName = className + ".class";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
URL codebaseURL = TestLibrary.
|
||||
installClassInCodebase(className, "codebase");
|
||||
|
||||
/* Create a URLClassLoader to load from the codebase and set it
|
||||
* as this thread's context class loader. We do not use the
|
||||
* URLClassLoader.newInstance() method so that the test will
|
||||
* compile with more early versions of the JDK.
|
||||
*
|
||||
* We can get away with creating a class loader like this
|
||||
* because there is no security manager set yet.
|
||||
*/
|
||||
ClassLoader codebaseLoader =
|
||||
new URLClassLoader(new URL[] { codebaseURL } );
|
||||
Thread.currentThread().setContextClassLoader(codebaseLoader);
|
||||
|
||||
File srcDir = new File(TestLibrary.getProperty("test.classes", "."));
|
||||
|
||||
URL dummyURL = new URL("file", "",
|
||||
srcDir.getAbsolutePath().replace(File.separatorChar, '/') +
|
||||
"/x-files/");
|
||||
|
||||
try {
|
||||
/*
|
||||
* Attempt to load the target class from the dummy URL;
|
||||
* it should be found in the context class loader.
|
||||
*/
|
||||
Class cl = RMIClassLoader.loadClass(dummyURL, className);
|
||||
System.err.println("TEST PASSED: loaded class: " + cl);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(
|
||||
"TEST FAILED: target class in context class loader " +
|
||||
"not found using RMIClassLoader");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
public class Dummy {
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4518927
|
||||
* @summary RMIClassLoader.getClassAnnotation() needs to specify behavior
|
||||
* for null class
|
||||
* @author Ann Wollrath
|
||||
*
|
||||
* @library ../../../testlibrary
|
||||
* @modules java.rmi/sun.rmi.registry
|
||||
* java.rmi/sun.rmi.server
|
||||
* java.rmi/sun.rmi.transport
|
||||
* java.rmi/sun.rmi.transport.tcp
|
||||
* @build TestLibrary
|
||||
* @run main/othervm NullClass
|
||||
*/
|
||||
|
||||
import java.rmi.server.RMIClassLoader;
|
||||
|
||||
public class NullClass {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.err.println("\nRegression test for bug 4518927\n");
|
||||
|
||||
try {
|
||||
System.err.println("getting class annotation for null class...");
|
||||
String annotation = RMIClassLoader.getClassAnnotation(null);
|
||||
throw new RuntimeException(
|
||||
"TEST FAILED: NullPointerException not caught!");
|
||||
} catch (NullPointerException e) {
|
||||
System.err.println("TEST PASSED: NullPointerException caught");
|
||||
} catch (Exception e) {
|
||||
TestLibrary.bomb(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.rmi.MarshalledObject;
|
||||
|
||||
public class FnnClass implements FnnUnmarshal {
|
||||
public Object unmarshal(MarshalledObject mobj)
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
return mobj.get();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.rmi.MarshalledObject;
|
||||
|
||||
public interface FnnUnmarshal {
|
||||
Object unmarshal(MarshalledObject mobj)
|
||||
throws IOException, ClassNotFoundException;
|
||||
}
|
||||
|
|
@ -0,0 +1,415 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 8280642
|
||||
* @summary functional test for RMIClassLoader.loadProxyClass; test
|
||||
* ensures that the default RMI class loader provider implements
|
||||
* RMIClassLoader.loadProxyClass correctly.
|
||||
*
|
||||
* @author Laird Dornin
|
||||
*
|
||||
* @library ../../../testlibrary
|
||||
* @modules java.rmi/sun.rmi.registry
|
||||
* java.rmi/sun.rmi.server
|
||||
* java.rmi/sun.rmi.transport
|
||||
* java.rmi/sun.rmi.transport.tcp
|
||||
* @build TestLibrary FnnClass FnnUnmarshal NonpublicInterface
|
||||
* NonpublicInterface1 PublicInterface PublicInterface1
|
||||
* @run main/othervm
|
||||
* -Djava.rmi.server.useCodebaseOnly=false LoadProxyClasses
|
||||
*/
|
||||
|
||||
import java.rmi.server.RMIClassLoader;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.rmi.MarshalledObject;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.io.Serializable;
|
||||
import java.io.InvalidClassException;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.zip.Checksum;
|
||||
|
||||
/**
|
||||
* Invokes RMIClassLoader.loadProxyClass() to load a proxy class with
|
||||
* multiple interfaces using RMI class unmarshalling. Test is
|
||||
* composed of cases which each unmarshal a proxy class in a
|
||||
* different environment. All of the cases create needed class
|
||||
* loaders, load appropriate interfaces, create a proxy class that
|
||||
* implements those interfaces, create a marshalled object from that
|
||||
* proxy class, and finally call .get() on that object. Get of the
|
||||
* object should pass in some cases and fail in others.
|
||||
*
|
||||
* 1. Nonpublic interface loaded from the parent of the First
|
||||
* Non-Null class Loader on the execution stack (FNNL). Public
|
||||
* interface loaded from grandparent of FNNL parent. Proxy class must
|
||||
* be defined in non-null FNNL parent. Should succeed.
|
||||
*
|
||||
* 2. Nonpublic interface (java.util.zip.ZipConstants) and public
|
||||
* interface (java.util.zip.CheckSum) loaded from bootclasspath,
|
||||
* proxy class defined in null/boot class loader. Should succeed.
|
||||
*
|
||||
* 3. Disabled. Public interface classes loaded in FNNL are also available in
|
||||
* RMI loader parent. FNNL is grandparent of RMI loader. Proxy class
|
||||
* must be defined in RMI class loader. Should succeed. public
|
||||
* interface must be defined in FNNL. Disabled because the default
|
||||
* RMIClassLoader provider no longer creates class loaders.
|
||||
*
|
||||
* 4. Non-public interfaces have multiple class loaders. Should fail
|
||||
* with a LinkageError.
|
||||
*
|
||||
* 5. Disabled. Interface classes loaded from RMI class loader. Proxy class
|
||||
* defined in RMI class loader. Disabled because the default RMIClassLoader
|
||||
* provider no longer creates class loaders.
|
||||
*
|
||||
* 6. Not all interfaces classes can be loaded from a single class
|
||||
* loader; should fail with ClassNotFoundException. All interface
|
||||
* classes will exist (but not all interfaces will be available from
|
||||
* one class loader).
|
||||
*
|
||||
* 7. prove that proxy loader has correct annotation.
|
||||
*
|
||||
* 8. REMIND: may want to add a case where the FNNL is null (This
|
||||
* would be for class unmarshalling in the implemntation of a remote
|
||||
* method invocation).
|
||||
*/
|
||||
public class LoadProxyClasses {
|
||||
|
||||
private static URL publicUrl = null;
|
||||
|
||||
public static boolean boomerangSemantics = false;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
System.err.println("\nFunctional test to verify that RMI " +
|
||||
"loads proxy classes correctly\n");
|
||||
|
||||
/* install proxy interfaces */
|
||||
publicUrl =
|
||||
TestLibrary.installClassInCodebase("PublicInterface",
|
||||
"public");
|
||||
URL publicUrl1 =
|
||||
TestLibrary.installClassInCodebase("PublicInterface1",
|
||||
"public1");
|
||||
URL nonpublicUrl =
|
||||
TestLibrary.installClassInCodebase("NonpublicInterface",
|
||||
"nonpublic", false);
|
||||
URL nonpublicUrl1 =
|
||||
TestLibrary.installClassInCodebase("NonpublicInterface1",
|
||||
"nonpublic1", false);
|
||||
URL bothNonpublicUrl =
|
||||
TestLibrary.installClassInCodebase("NonpublicInterface",
|
||||
"bothNonpublic");
|
||||
TestLibrary.installClassInCodebase("NonpublicInterface1",
|
||||
"bothNonpublic");
|
||||
URL fnnUrl =
|
||||
TestLibrary.installClassInCodebase("FnnClass", "fnn");
|
||||
|
||||
/* Case 1 */
|
||||
ClassLoader grandParentPublic =
|
||||
new URLClassLoader(new URL[] {publicUrl});
|
||||
ClassLoader parentNonpublic =
|
||||
new URLClassLoader(new URL[] {nonpublicUrl},
|
||||
grandParentPublic);
|
||||
URLClassLoader fnnLoader1 =
|
||||
new URLClassLoader(new URL[] {fnnUrl}, parentNonpublic);
|
||||
|
||||
Class nonpublicInterface =
|
||||
fnnLoader1.loadClass("NonpublicInterface");
|
||||
Class publicInterface =
|
||||
fnnLoader1.loadClass("PublicInterface");
|
||||
|
||||
Proxy proxy1 = (Proxy) Proxy.newProxyInstance(parentNonpublic,
|
||||
new Class[] {nonpublicInterface, publicInterface},
|
||||
new TestInvocationHandler());
|
||||
unmarshalProxyClass(proxy1, fnnLoader1, parentNonpublic, 1, null);
|
||||
|
||||
|
||||
|
||||
/* Case 2 */
|
||||
Class zipConstantsClass =
|
||||
Class.forName("java.util.zip.ZipConstants");
|
||||
URLClassLoader fnnLoader2 =
|
||||
new URLClassLoader(new URL[] {fnnUrl});
|
||||
Proxy proxy2 = (Proxy) Proxy.newProxyInstance(null,
|
||||
new Class[] {zipConstantsClass, Checksum.class},
|
||||
new TestInvocationHandler());
|
||||
unmarshalProxyClass(proxy2, fnnLoader2,
|
||||
(ClassLoader) null, 2, null);
|
||||
|
||||
|
||||
|
||||
/* Case 3 */
|
||||
Thread currentThread = Thread.currentThread();
|
||||
ClassLoader fnnLoader3 = new URLClassLoader(
|
||||
new URL[] {publicUrl, fnnUrl});
|
||||
ClassLoader newCtxLoader =
|
||||
new URLClassLoader(new URL[] {publicUrl}, fnnLoader3);
|
||||
Class publicInterface3 =
|
||||
fnnLoader3.loadClass("PublicInterface");
|
||||
ClassLoader currentCtxLoader =
|
||||
currentThread.getContextClassLoader();
|
||||
currentThread.setContextClassLoader(newCtxLoader);
|
||||
|
||||
Proxy proxy3 = (Proxy) Proxy.newProxyInstance(newCtxLoader,
|
||||
new Class[] {publicInterface3},
|
||||
new TestInvocationHandler());
|
||||
|
||||
// unmarshalProxyClass(proxy3, fnnLoader3, fnnLoader3,
|
||||
// 3, new Case3Checker());
|
||||
|
||||
currentThread.setContextClassLoader(currentCtxLoader);
|
||||
|
||||
|
||||
|
||||
/* Case 4 */
|
||||
ClassLoader bothNonpublicLoader =
|
||||
new URLClassLoader(new URL[] {bothNonpublicUrl});
|
||||
Class nonpublicInterface4a =
|
||||
bothNonpublicLoader.loadClass("NonpublicInterface");
|
||||
Class nonpublicInterface4b =
|
||||
bothNonpublicLoader.loadClass("NonpublicInterface1");
|
||||
Proxy proxy4 = (Proxy) Proxy.newProxyInstance(bothNonpublicLoader,
|
||||
new Class[] {nonpublicInterface4a, nonpublicInterface4b},
|
||||
new TestInvocationHandler());
|
||||
|
||||
ClassLoader nonpublicLoaderA =
|
||||
new URLClassLoader(new URL[] {nonpublicUrl});
|
||||
ClassLoader nonpublicLoaderB =
|
||||
new URLClassLoader(new URL[] {nonpublicUrl1}, nonpublicLoaderA);
|
||||
currentCtxLoader =
|
||||
currentThread.getContextClassLoader();
|
||||
currentThread.setContextClassLoader(nonpublicLoaderB);
|
||||
|
||||
InvalidClassException invalid = null;
|
||||
try {
|
||||
unmarshalProxyClass(proxy4, fnnLoader2, nonpublicLoaderB,
|
||||
4, null);
|
||||
} catch (InvalidClassException e) {
|
||||
invalid = e;
|
||||
}
|
||||
|
||||
if (invalid == null) {
|
||||
TestLibrary.bomb("case4: InvalidClassException not thrown " +
|
||||
"when multiple nonpublic interfaces have \n" +
|
||||
"different class loaders");
|
||||
} else {
|
||||
System.err.println("\ncase4: InvalidClassException correctly " +
|
||||
"thrown \n when trying to load proxy " +
|
||||
"with multiple nonpublic interfaces in \n" +
|
||||
" different class loaders");
|
||||
}
|
||||
currentThread.setContextClassLoader(currentCtxLoader);
|
||||
|
||||
|
||||
|
||||
/* Case 5*/
|
||||
ClassLoader publicLoader =
|
||||
new URLClassLoader(new URL[] {publicUrl});
|
||||
Class publicInterface5 =
|
||||
publicLoader.loadClass("PublicInterface");
|
||||
Proxy proxy5 = (Proxy) Proxy.newProxyInstance(publicLoader,
|
||||
new Class[] {publicInterface5},
|
||||
new TestInvocationHandler());
|
||||
|
||||
currentCtxLoader =
|
||||
currentThread.getContextClassLoader();
|
||||
currentThread.setContextClassLoader(publicLoader);
|
||||
// unmarshalProxyClass(proxy5, fnnLoader2, publicLoader, 5,
|
||||
// new Case5Checker());
|
||||
currentThread.setContextClassLoader(currentCtxLoader);
|
||||
|
||||
|
||||
|
||||
/* Case 6 */
|
||||
ClassLoader fnnLoader6 =
|
||||
new URLClassLoader(new URL[] {fnnUrl, publicUrl});
|
||||
ClassLoader publicLoader6 =
|
||||
new URLClassLoader(new URL[] {publicUrl1}, fnnLoader6);
|
||||
|
||||
Class publicInterface6a =
|
||||
publicLoader6.loadClass("PublicInterface1");
|
||||
Class publicInterface6b =
|
||||
fnnLoader6.loadClass("PublicInterface");
|
||||
Proxy proxy6 = (Proxy) Proxy.newProxyInstance(publicLoader6,
|
||||
new Class[] {publicInterface6a, publicInterface6b},
|
||||
new TestInvocationHandler());
|
||||
ClassNotFoundException cnfe = null;
|
||||
try {
|
||||
unmarshalProxyClass(proxy6, fnnLoader6, publicLoader6, 6,
|
||||
null);
|
||||
} catch (ClassNotFoundException e) {
|
||||
cnfe = e;
|
||||
}
|
||||
if (cnfe == null) {
|
||||
TestLibrary.bomb("ClassNotFoundException not thrown " +
|
||||
"when not all proxy interfaces could " +
|
||||
" be found in a single class loader ");
|
||||
} else {
|
||||
System.err.println("Case6: ClassNotFoundException " +
|
||||
"correctly thrown when not all proxy" +
|
||||
" interfaces could be found in a " +
|
||||
"single class loader");
|
||||
cnfe.printStackTrace();
|
||||
}
|
||||
|
||||
System.err.println("TEST PASSED");
|
||||
|
||||
} catch (Exception e) {
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
TestLibrary.bomb(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private interface LoadChecker {
|
||||
void checkLoad(Proxy proxy, ClassLoader expectedLoader);
|
||||
}
|
||||
|
||||
private static Proxy unmarshalProxyClass(Proxy proxy,
|
||||
ClassLoader fnnLoader,
|
||||
ClassLoader expectedLoader,
|
||||
int n,
|
||||
LoadChecker checker)
|
||||
throws ClassNotFoundException, IOException,
|
||||
InstantiationException, IllegalAccessException
|
||||
{
|
||||
FnnUnmarshal fnnUnmarshal = (FnnUnmarshal)
|
||||
fnnLoader.loadClass("FnnClass").newInstance();
|
||||
Proxy unmarshalled = (Proxy)
|
||||
fnnUnmarshal.unmarshal(new MarshalledObject(proxy));
|
||||
ClassLoader unmarshalledLoader =
|
||||
unmarshalled.getClass().getClassLoader();
|
||||
|
||||
if (checker != null) {
|
||||
checker.checkLoad(unmarshalled, expectedLoader);
|
||||
} else {
|
||||
if (unmarshalledLoader != expectedLoader) {
|
||||
TestLibrary.bomb("case" + n + ": proxy class not " +
|
||||
"placed into incorrect loader: " +
|
||||
unmarshalledLoader);
|
||||
} else {
|
||||
System.err.println("\ncase" + n + ": proxy class correctly" +
|
||||
" placed into expected loader: " +
|
||||
expectedLoader);
|
||||
}
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
private static class Case3Checker implements LoadChecker {
|
||||
public void checkLoad(Proxy proxy, ClassLoader expectedLoader) {
|
||||
ClassLoader ifaceLoader =
|
||||
proxy.getClass().getInterfaces()[0].getClassLoader();
|
||||
ClassLoader proxyLoader = proxy.getClass().getClassLoader();
|
||||
|
||||
boolean proxyOk = false;
|
||||
|
||||
if (boomerangSemantics) {
|
||||
ClassLoader ctxLoader =
|
||||
Thread.currentThread().getContextClassLoader();
|
||||
if (proxyLoader == ctxLoader) {
|
||||
proxyOk = true;
|
||||
}
|
||||
} else if (proxyLoader.getClass().
|
||||
getName().indexOf("sun.rmi") >= 0)
|
||||
{
|
||||
proxyOk = true;
|
||||
}
|
||||
|
||||
if (proxyOk) {
|
||||
System.err.println("\ncase3: proxy loaded in" +
|
||||
" correct loader: " + proxyLoader +
|
||||
Arrays.asList(((URLClassLoader)
|
||||
proxyLoader).getURLs()));
|
||||
} else {
|
||||
TestLibrary.bomb("case3: proxy class loaded in " +
|
||||
"incorrect loader: " + proxyLoader +
|
||||
Arrays.asList(((URLClassLoader)
|
||||
proxyLoader).getURLs()));
|
||||
}
|
||||
|
||||
if (ifaceLoader == expectedLoader) {
|
||||
System.err.println("case3: proxy interface loaded in" +
|
||||
" correct loader: " + ifaceLoader);
|
||||
} else {
|
||||
TestLibrary.bomb("public proxy interface loaded in " +
|
||||
"incorrect loader: " + ifaceLoader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class Case5Checker implements LoadChecker {
|
||||
public void checkLoad(Proxy proxy, ClassLoader expectedLoader) {
|
||||
ClassLoader proxyLoader = proxy.getClass().getClassLoader();
|
||||
|
||||
String proxyAnnotation =
|
||||
RMIClassLoader.getClassAnnotation(proxy.getClass());
|
||||
|
||||
if ((proxyAnnotation == null) ||
|
||||
!proxyAnnotation.equals(publicUrl.toString()))
|
||||
{
|
||||
TestLibrary.bomb("proxy class had incorrect annotation: " +
|
||||
proxyAnnotation);
|
||||
} else {
|
||||
System.err.println("proxy class had correct annotation: " +
|
||||
proxyAnnotation);
|
||||
}
|
||||
|
||||
boolean proxyOk = false;
|
||||
|
||||
if (boomerangSemantics) {
|
||||
ClassLoader ctxLoader =
|
||||
Thread.currentThread().getContextClassLoader();
|
||||
if (proxyLoader == ctxLoader) {
|
||||
proxyOk = true;
|
||||
}
|
||||
} else if (proxyLoader.getClass().
|
||||
getName().indexOf("sun.rmi") >= 0)
|
||||
{
|
||||
proxyOk = true;
|
||||
}
|
||||
|
||||
if (proxyOk) {
|
||||
System.err.println("\ncase5: proxy loaded from" +
|
||||
" correct loader: " + proxyLoader);
|
||||
} else {
|
||||
TestLibrary.bomb("case5: proxy interface loaded from " +
|
||||
"incorrect loader: " + proxyLoader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestInvocationHandler
|
||||
implements InvocationHandler, Serializable
|
||||
{
|
||||
public Object invoke(Object proxy, Method method, Object[] args)
|
||||
throws Throwable {return null;}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
interface NonpublicInterface {}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
interface NonpublicInterface1 {}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
public interface PublicInterface {}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
public interface PublicInterface1 {}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
public class Dummy {
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
public class LocalDummy {
|
||||
}
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4140511
|
||||
* @summary RMIClassLoader's loadClass() methods, when there is no security
|
||||
* manager installed, should not create or use RMI class loader instances for
|
||||
* the requested codebases, but they should still succeed to load classes
|
||||
* that can be found by delegation to parent class loader that would have
|
||||
* been used for the RMI class loader instance.
|
||||
* @author Peter Jones
|
||||
*
|
||||
* @build Dummy LocalDummy
|
||||
* @run main/othervm/timeout=120 NoSecurityManager
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.rmi.server.RMIClassLoader;
|
||||
|
||||
/**
|
||||
* NoSecurityManager verifies the behavior of the RMIClassLoader.loadClass()
|
||||
* methods when there is no security manager installed in JDK1.2 as prescribed
|
||||
* by RFE 4140511.
|
||||
*
|
||||
* First, a class installed in a codebase (and not in the test's class path)
|
||||
* is loaded using RMIClassLoader.loadClass(); this should fail with a
|
||||
* ClassNotFoundException (it failed with a SecurityException in JDK 1.1).
|
||||
*
|
||||
* Second, a class installed in the test's class path is loaded using
|
||||
* RMIClassLoader.loadClass(), which should succeed (again, this used
|
||||
* to fail with a SecurityException in JDK 1.1).
|
||||
*/
|
||||
public class NoSecurityManager {
|
||||
|
||||
/** name of target class to attempt to load */
|
||||
private static final String className = "Dummy";
|
||||
|
||||
/** name of file containing definition for target class */
|
||||
private static final String classFileName = className + ".class";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
/*
|
||||
* Specify the file to contain the class definition.
|
||||
* Make sure that there is a "classes" subdirectory underneath
|
||||
* the working directory to be used as the codebase for the
|
||||
* class definition to be located.
|
||||
*/
|
||||
File dstDir = new File(System.getProperty("user.dir"), "codebase");
|
||||
if (!dstDir.exists()) {
|
||||
if (!dstDir.mkdir()) {
|
||||
throw new RuntimeException(
|
||||
"could not create codebase directory");
|
||||
}
|
||||
}
|
||||
File dstFile = new File(dstDir, classFileName);
|
||||
|
||||
/*
|
||||
* Specify where we will copy the class definition from, if
|
||||
* necessary. After the test is built, the class file can be
|
||||
* found in the "test.classes" directory.
|
||||
*/
|
||||
File srcDir = new File(System.getProperty("test.classes", "."));
|
||||
File srcFile = new File(srcDir, classFileName);
|
||||
|
||||
/*
|
||||
* If the class definition is not already located at the codebase,
|
||||
* copy it there from the test build area.
|
||||
*/
|
||||
if (!dstFile.exists()) {
|
||||
if (!srcFile.exists()) {
|
||||
throw new RuntimeException(
|
||||
"could not find class file to install in codebase " +
|
||||
"(try rebuilding the test)");
|
||||
}
|
||||
if (!srcFile.renameTo(dstFile)) {
|
||||
throw new RuntimeException(
|
||||
"could not install class file in codebase");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* After the class definition is successfully installed at the
|
||||
* codebase, delete it from the test's CLASSPATH, so that it will
|
||||
* not be found there first before the codebase is searched.
|
||||
*/
|
||||
if (srcFile.exists()) {
|
||||
if (!srcFile.delete()) {
|
||||
throw new RuntimeException(
|
||||
"could not delete duplicate class file in CLASSPATH");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Obtain the URL for the codebase.
|
||||
*/
|
||||
URL codebaseURL = new URL("file", "",
|
||||
dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/");
|
||||
|
||||
/*
|
||||
* No security manager has been set: verify that we cannot load
|
||||
* a class from a specified codebase (that is not in the class path).
|
||||
*/
|
||||
try {
|
||||
RMIClassLoader.loadClass(codebaseURL, className);
|
||||
throw new RuntimeException(
|
||||
"TEST FAILED: class loaded successfully from codebase");
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.err.println(e.toString());
|
||||
}
|
||||
|
||||
/*
|
||||
* No security manager has been set: verify that we can still
|
||||
* load a class available in the context class loader (class path).
|
||||
*/
|
||||
RMIClassLoader.loadClass(codebaseURL, "LocalDummy");
|
||||
System.err.println("TEST PASSED: local class loaded successfully");
|
||||
|
||||
/*
|
||||
* Verify that getClassLoader returns context class loader
|
||||
* if no security manager is set.
|
||||
*/
|
||||
System.err.println("/nTest getClassLoader with no security manager set");
|
||||
ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase");
|
||||
if (loader == Thread.currentThread().getContextClassLoader()) {
|
||||
System.err.println("TEST PASSED: returned context class loader");
|
||||
} else {
|
||||
throw new RuntimeException(
|
||||
"TEST FAILED: returned RMI-created class loader");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4418673
|
||||
* @summary verify that setting the java.rmi.server.RMIClassLoaderSpi
|
||||
* system property to "default" causes the default provider instance to
|
||||
* be used by the RMIClassLoader API.
|
||||
* @author Peter Jones
|
||||
*
|
||||
* @library ../../../testlibrary
|
||||
* @modules java.rmi/java.rmi.server:+open
|
||||
* java.rmi/sun.rmi.registry
|
||||
* java.rmi/sun.rmi.server
|
||||
* java.rmi/sun.rmi.transport
|
||||
* java.rmi/sun.rmi.transport.tcp
|
||||
* @build TestLibrary ServiceConfiguration
|
||||
* @run main/othervm DefaultProperty
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.rmi.server.RMIClassLoader;
|
||||
import java.rmi.server.RMIClassLoaderSpi;
|
||||
|
||||
public class DefaultProperty {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ServiceConfiguration.installServiceConfigurationFile();
|
||||
|
||||
System.setProperty(
|
||||
"java.rmi.server.RMIClassLoaderSpi", "default");
|
||||
|
||||
// Force loading of RMIClassLoader, which will initialize the
|
||||
// provider instance.
|
||||
RMIClassLoaderSpi def = RMIClassLoader.getDefaultProviderInstance();
|
||||
|
||||
Field fProvider = RMIClassLoader.class.getDeclaredField("provider");
|
||||
fProvider.setAccessible(true);
|
||||
RMIClassLoaderSpi actual = (RMIClassLoaderSpi) fProvider.get(null);
|
||||
|
||||
if (def != actual) {
|
||||
System.err.println("TEST FAILED");
|
||||
System.err.println("default provider = " + def);
|
||||
System.err.println("actual provider = " + actual);
|
||||
throw new AssertionError("TEST FAILED");
|
||||
}
|
||||
|
||||
System.err.println("TEST PASSED");
|
||||
}
|
||||
}
|
||||
25
test/jdk/java/rmi/server/RMIClassLoader/spi/Foo.java
Normal file
25
test/jdk/java/rmi/server/RMIClassLoader/spi/Foo.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
public class Foo {
|
||||
}
|
||||
52
test/jdk/java/rmi/server/RMIClassLoader/spi/Installed.java
Normal file
52
test/jdk/java/rmi/server/RMIClassLoader/spi/Installed.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4418673
|
||||
* @summary verify that with the java.rmi.server.RMIClassLoaderSpi system
|
||||
* property not set, the first provider located through java.util.ServiceLoader
|
||||
* (which should be "TestProvider2") will be used by the RMIClassLoader API.
|
||||
* @author Peter Jones
|
||||
*
|
||||
* @library ../../../testlibrary
|
||||
* @modules java.rmi/sun.rmi.registry
|
||||
* java.rmi/sun.rmi.server
|
||||
* java.rmi/sun.rmi.transport
|
||||
* java.rmi/sun.rmi.transport.tcp
|
||||
* @build TestLibrary ServiceConfiguration TestProvider TestProvider2
|
||||
* @run main/othervm Installed
|
||||
*/
|
||||
|
||||
public class Installed {
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ServiceConfiguration.installServiceConfigurationFile();
|
||||
|
||||
TestProvider.exerciseTestProvider(
|
||||
TestProvider2.loadClassReturn,
|
||||
TestProvider2.loadProxyClassReturn,
|
||||
TestProvider2.getClassLoaderReturn,
|
||||
TestProvider2.getClassAnnotationReturn,
|
||||
TestProvider2.invocations);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4418673
|
||||
* @summary verify that an inavlid setting of the system property
|
||||
* java.rmi.server.RMIClassLoaderSpi causes an Error to be thrown to users
|
||||
* of the RMIClassLoader API.
|
||||
* @author Peter Jones
|
||||
*
|
||||
* @library ../../../testlibrary
|
||||
* @modules java.rmi/sun.rmi.registry
|
||||
* java.rmi/sun.rmi.server
|
||||
* java.rmi/sun.rmi.transport
|
||||
* java.rmi/sun.rmi.transport.tcp
|
||||
* @build TestLibrary ServiceConfiguration
|
||||
* @run main/othervm InvalidProperty
|
||||
*/
|
||||
|
||||
import java.rmi.server.RMIClassLoader;
|
||||
|
||||
public class InvalidProperty {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ServiceConfiguration.installServiceConfigurationFile();
|
||||
|
||||
System.setProperty(
|
||||
"java.rmi.server.RMIClassLoaderSpi", "NonexistentProvider");
|
||||
|
||||
String classname = "Foo";
|
||||
|
||||
try {
|
||||
System.err.println("first attempt:");
|
||||
Object ret;
|
||||
try {
|
||||
ret = RMIClassLoader.loadClass(classname);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(
|
||||
"RMIClassLoader.loadClass threw exception", e);
|
||||
}
|
||||
throw new RuntimeException(
|
||||
"RMIClassLoader.loadClass returned " + ret);
|
||||
} catch (Error e) {
|
||||
System.err.println("RMIClassLoader.loadClass threw an Error:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
System.err.println("second attempt:");
|
||||
Object ret;
|
||||
try {
|
||||
ret = RMIClassLoader.loadClass(classname);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(
|
||||
"RMIClassLoader.loadClass threw exception", e);
|
||||
}
|
||||
throw new RuntimeException(
|
||||
"RMIClassLoader.loadClass returned " + ret);
|
||||
} catch (Error e) {
|
||||
System.err.println("RMIClassLoader.loadClass threw an Error:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.err.println("TEST PASSED");
|
||||
}
|
||||
}
|
||||
55
test/jdk/java/rmi/server/RMIClassLoader/spi/Property.java
Normal file
55
test/jdk/java/rmi/server/RMIClassLoader/spi/Property.java
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4418673
|
||||
* @summary verify that the value of the java.rmi.server.RMIClassLoaderSpi
|
||||
* system property is interpreted to name the class to instantiate for the
|
||||
* RMIClassLoader provider.
|
||||
* @author Peter Jones
|
||||
*
|
||||
* @library ../../../testlibrary
|
||||
* @modules java.rmi/sun.rmi.registry
|
||||
* java.rmi/sun.rmi.server
|
||||
* java.rmi/sun.rmi.transport
|
||||
* java.rmi/sun.rmi.transport.tcp
|
||||
* @build TestLibrary ServiceConfiguration TestProvider
|
||||
* @run main/othervm Property
|
||||
*/
|
||||
|
||||
public class Property {
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ServiceConfiguration.installServiceConfigurationFile();
|
||||
|
||||
System.setProperty(
|
||||
"java.rmi.server.RMIClassLoaderSpi", "TestProvider");
|
||||
|
||||
TestProvider.exerciseTestProvider(
|
||||
TestProvider.loadClassReturn,
|
||||
TestProvider.loadProxyClassReturn,
|
||||
TestProvider.getClassLoaderReturn,
|
||||
TestProvider.getClassAnnotationReturn,
|
||||
TestProvider.invocations);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ServiceConfiguration {
|
||||
public static void installServiceConfigurationFile() {
|
||||
String filename = "java.rmi.server.RMIClassLoaderSpi";
|
||||
|
||||
File dstDir = new File(TestLibrary.getProperty("test.classes", "."),
|
||||
"META-INF/services");
|
||||
if (!dstDir.exists()) {
|
||||
if (!dstDir.mkdirs()) {
|
||||
throw new RuntimeException(
|
||||
"could not create META-INF/services directory " + dstDir);
|
||||
}
|
||||
}
|
||||
File dstFile = new File(dstDir, filename);
|
||||
|
||||
File srcDir = new File(TestLibrary.getProperty("test.src", "."));
|
||||
File srcFile = new File(srcDir, filename);
|
||||
|
||||
try {
|
||||
TestLibrary.copyFile(srcFile, dstFile);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("could not install " + dstFile, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
278
test/jdk/java/rmi/server/RMIClassLoader/spi/TestProvider.java
Normal file
278
test/jdk/java/rmi/server/RMIClassLoader/spi/TestProvider.java
Normal file
|
|
@ -0,0 +1,278 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import java.rmi.server.RMIClassLoader;
|
||||
import java.rmi.server.RMIClassLoaderSpi;
|
||||
|
||||
public class TestProvider extends RMIClassLoaderSpi {
|
||||
|
||||
public static final Method loadClassMethod;
|
||||
public static final Method loadProxyClassMethod;
|
||||
public static final Method getClassLoaderMethod;
|
||||
public static final Method getClassAnnotationMethod;
|
||||
static {
|
||||
try {
|
||||
loadClassMethod = RMIClassLoaderSpi.class.getMethod(
|
||||
"loadClass", new Class[] {
|
||||
String.class, String.class, ClassLoader.class
|
||||
});
|
||||
loadProxyClassMethod = RMIClassLoaderSpi.class.getMethod(
|
||||
"loadProxyClass", new Class[] {
|
||||
String.class, String[].class, ClassLoader.class
|
||||
});
|
||||
getClassLoaderMethod = RMIClassLoaderSpi.class.getMethod(
|
||||
"getClassLoader", new Class[] { String.class });
|
||||
getClassAnnotationMethod = RMIClassLoaderSpi.class.getMethod(
|
||||
"getClassAnnotation", new Class[] { Class.class });
|
||||
} catch (NoSuchMethodException e) {
|
||||
Error error = new NoSuchMethodError();
|
||||
error.initCause(e);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
public static final Class loadClassReturn =
|
||||
(new Object() { }).getClass();
|
||||
public static final Class loadProxyClassReturn =
|
||||
(new Object() { }).getClass();
|
||||
public static final ClassLoader getClassLoaderReturn =
|
||||
URLClassLoader.newInstance(new URL[0]);
|
||||
public static final String getClassAnnotationReturn = new String();
|
||||
|
||||
public static List invocations =
|
||||
Collections.synchronizedList(new ArrayList(1));
|
||||
|
||||
public TestProvider() {
|
||||
System.err.println("TestProvider()");
|
||||
}
|
||||
|
||||
public Class loadClass(String codebase, String name,
|
||||
ClassLoader defaultLoader)
|
||||
throws MalformedURLException, ClassNotFoundException
|
||||
{
|
||||
invocations.add(new Invocation(loadClassMethod,
|
||||
new Object[] { codebase, name, defaultLoader }));
|
||||
|
||||
return loadClassReturn;
|
||||
}
|
||||
|
||||
public Class loadProxyClass(String codebase, String[] interfaces,
|
||||
ClassLoader defaultLoader)
|
||||
throws MalformedURLException, ClassNotFoundException
|
||||
{
|
||||
invocations.add(new Invocation(loadProxyClassMethod,
|
||||
new Object[] { codebase, interfaces, defaultLoader }));
|
||||
|
||||
return loadProxyClassReturn;
|
||||
}
|
||||
|
||||
public ClassLoader getClassLoader(String codebase)
|
||||
throws MalformedURLException
|
||||
{
|
||||
invocations.add(new Invocation(
|
||||
getClassLoaderMethod, new Object[] { codebase }));
|
||||
|
||||
return getClassLoaderReturn;
|
||||
}
|
||||
|
||||
public String getClassAnnotation(Class<?> cl) {
|
||||
invocations.add(new Invocation(
|
||||
getClassAnnotationMethod, new Object[] { cl }));
|
||||
|
||||
return getClassAnnotationReturn;
|
||||
}
|
||||
|
||||
public static class Invocation {
|
||||
public Method method;
|
||||
public Object[] args;
|
||||
|
||||
public Invocation(Method method, Object[] args) {
|
||||
this.method = method;
|
||||
this.args = (Object[]) args.clone();
|
||||
}
|
||||
}
|
||||
|
||||
public static void exerciseTestProvider(Object loadClassReturn,
|
||||
Object loadProxyClassReturn,
|
||||
Object getClassLoaderReturn,
|
||||
Object getClassAnnotationReturn,
|
||||
List invocationQueue)
|
||||
throws MalformedURLException, ClassNotFoundException
|
||||
{
|
||||
URL codebaseURL = new URL("http://the-black-lodge/dale-cooper/");
|
||||
String codebase = codebaseURL.toString();
|
||||
String classname = "Foo";
|
||||
ClassLoader defaultLoader = URLClassLoader.newInstance(new URL[0]);
|
||||
String[] interfaces = new String[] { "Bar", "Baz" };
|
||||
Class dummyClass = (new Object() { }).getClass();
|
||||
|
||||
String testcase;
|
||||
Object ret;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
testcase = "RMIClassLoader.loadClass(String)";
|
||||
System.err.println("testing " + testcase);
|
||||
|
||||
ret = RMIClassLoader.loadClass(classname);
|
||||
if (ret != loadClassReturn) {
|
||||
throw new RuntimeException("TEST FAILED: " +
|
||||
testcase + " returned " + ret);
|
||||
}
|
||||
verifyOneInvocation(TestProvider.loadClassMethod,
|
||||
new Object[] { null, classname, null }, invocationQueue);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
testcase = "RMIClassLoader.loadClass(URL,String)";
|
||||
System.err.println("testing " + testcase);
|
||||
|
||||
ret = RMIClassLoader.loadClass(codebaseURL, classname);
|
||||
if (ret != loadClassReturn) {
|
||||
throw new RuntimeException("TEST FAILED: " +
|
||||
testcase + " returned " + ret);
|
||||
}
|
||||
verifyOneInvocation(TestProvider.loadClassMethod,
|
||||
new Object[] { codebase, classname, null }, invocationQueue);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
testcase = "RMIClassLoader.loadClass(String,String)";
|
||||
System.err.println("testing " + testcase);
|
||||
|
||||
ret = RMIClassLoader.loadClass(codebase, classname);
|
||||
if (ret != loadClassReturn) {
|
||||
throw new RuntimeException("TEST FAILED: " +
|
||||
testcase + " returned " + ret);
|
||||
}
|
||||
verifyOneInvocation(TestProvider.loadClassMethod,
|
||||
new Object[] { codebase, classname, null }, invocationQueue);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
testcase = "RMIClassLoader.loadClass(String,String,ClassLoader";
|
||||
System.err.println("testing " + testcase);
|
||||
|
||||
ret = RMIClassLoader.loadClass(codebase, classname, defaultLoader);
|
||||
if (ret != loadClassReturn) {
|
||||
throw new RuntimeException("TEST FAILED: " +
|
||||
testcase + " returned " + ret);
|
||||
}
|
||||
verifyOneInvocation(TestProvider.loadClassMethod,
|
||||
new Object[] { codebase, classname, defaultLoader },
|
||||
invocationQueue);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
testcase =
|
||||
"RMIClassLoader.loadProxyClass(String,String[],ClassLoader)";
|
||||
System.err.println("testing " + testcase);
|
||||
|
||||
ret = RMIClassLoader.loadProxyClass(codebase, interfaces,
|
||||
defaultLoader);
|
||||
if (ret != loadProxyClassReturn) {
|
||||
throw new RuntimeException("TEST FAILED: " +
|
||||
testcase + " returned " + ret);
|
||||
}
|
||||
verifyOneInvocation(TestProvider.loadProxyClassMethod,
|
||||
new Object[] { codebase, interfaces, defaultLoader },
|
||||
invocationQueue);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
testcase = "RMIClassLoader.getClassLoader(String)";
|
||||
System.err.println("testing " + testcase);
|
||||
|
||||
ret = RMIClassLoader.getClassLoader(codebase);
|
||||
if (ret != getClassLoaderReturn) {
|
||||
throw new RuntimeException("TEST FAILED: " +
|
||||
testcase + " returned " + ret);
|
||||
}
|
||||
verifyOneInvocation(TestProvider.getClassLoaderMethod,
|
||||
new Object[] { codebase }, invocationQueue);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
testcase = "RMIClassLoader.getClassAnnotation(Class)";
|
||||
System.err.println("testing " + testcase);
|
||||
|
||||
ret = RMIClassLoader.getClassAnnotation(dummyClass);
|
||||
if (ret != getClassAnnotationReturn) {
|
||||
throw new RuntimeException("TEST FAILED: " +
|
||||
testcase + " returned " + ret);
|
||||
}
|
||||
verifyOneInvocation(TestProvider.getClassAnnotationMethod,
|
||||
new Object[] { dummyClass }, invocationQueue);
|
||||
|
||||
System.err.println("TEST PASSED");
|
||||
}
|
||||
|
||||
private static void verifyOneInvocation(Method method, Object[] args,
|
||||
List invocationQueue)
|
||||
{
|
||||
TestProvider.Invocation inv =
|
||||
(TestProvider.Invocation) invocationQueue.remove(0);
|
||||
|
||||
if (!method.equals(inv.method)) {
|
||||
throw new RuntimeException(
|
||||
"unexpected provider method invoked: expected " + method +
|
||||
", detected " + inv.method);
|
||||
}
|
||||
|
||||
List expectedArgs = Arrays.asList(args);
|
||||
List detectedArgs = Arrays.asList(inv.args);
|
||||
if (!expectedArgs.equals(detectedArgs)) {
|
||||
throw new RuntimeException("TEST FAILED: " +
|
||||
"unexpected provider method invocation arguments: " +
|
||||
"expected " + expectedArgs + ", detected " + detectedArgs);
|
||||
}
|
||||
|
||||
if (!invocationQueue.isEmpty()) {
|
||||
inv = (TestProvider.Invocation)
|
||||
invocationQueue.remove(0);
|
||||
throw new RuntimeException("TEST FAILED: " +
|
||||
"unexpected provider invocation: " + inv.method + " " +
|
||||
Arrays.asList(inv.args));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import java.rmi.server.RMIClassLoader;
|
||||
import java.rmi.server.RMIClassLoaderSpi;
|
||||
|
||||
/**
|
||||
* TestProvider2 extends TestProvider with very similar behavior, but
|
||||
* with its own static fields, to allow a test to distinguish between
|
||||
* an installed TestProvider2 being used, or a property-specified
|
||||
* TestProvider being used.
|
||||
*/
|
||||
public class TestProvider2 extends TestProvider {
|
||||
|
||||
public static final Class loadClassReturn =
|
||||
(new Object() { }).getClass();
|
||||
public static final Class loadProxyClassReturn =
|
||||
(new Object() { }).getClass();
|
||||
public static final ClassLoader getClassLoaderReturn =
|
||||
URLClassLoader.newInstance(new URL[0]);
|
||||
public static final String getClassAnnotationReturn = new String();
|
||||
|
||||
public static List invocations =
|
||||
Collections.synchronizedList(new ArrayList(1));
|
||||
|
||||
public TestProvider2() {
|
||||
System.err.println("TestProvider2()");
|
||||
}
|
||||
|
||||
public Class loadClass(String codebase, String name,
|
||||
ClassLoader defaultLoader)
|
||||
throws MalformedURLException, ClassNotFoundException
|
||||
{
|
||||
invocations.add(new Invocation(loadClassMethod,
|
||||
new Object[] { codebase, name, defaultLoader }));
|
||||
|
||||
return loadClassReturn;
|
||||
}
|
||||
|
||||
public Class loadProxyClass(String codebase, String[] interfaces,
|
||||
ClassLoader defaultLoader)
|
||||
throws MalformedURLException, ClassNotFoundException
|
||||
{
|
||||
invocations.add(new Invocation(loadProxyClassMethod,
|
||||
new Object[] { codebase, interfaces, defaultLoader }));
|
||||
|
||||
return loadProxyClassReturn;
|
||||
}
|
||||
|
||||
public ClassLoader getClassLoader(String codebase)
|
||||
throws MalformedURLException
|
||||
{
|
||||
invocations.add(new Invocation(
|
||||
getClassLoaderMethod, new Object[] { codebase }));
|
||||
|
||||
return getClassLoaderReturn;
|
||||
}
|
||||
|
||||
public String getClassAnnotation(Class<?> cl) {
|
||||
invocations.add(new Invocation(
|
||||
getClassAnnotationMethod, new Object[] { cl }));
|
||||
|
||||
return getClassAnnotationReturn;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
TestProvider2
|
||||
TestProvider3
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
public class Bar implements java.io.Serializable {
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
public class Foo implements java.io.Serializable {
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
public interface Receiver extends Remote {
|
||||
public void receive(Object obj) throws RemoteException;
|
||||
}
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4174006
|
||||
* @summary If the "java.rmi.server.useCodebaseOnly" property has a boolean
|
||||
* value of true, then when the RMI runtime is unmarshalling a class
|
||||
* descriptor, it should not attempt to download the associate Class object
|
||||
* from the annotated codebase, but only from the codebase specified in the
|
||||
* "java.rmi.server.codebase" property and the context class loader.
|
||||
* @author Peter Jones
|
||||
*
|
||||
* @library ../../../testlibrary
|
||||
* @modules java.rmi/sun.rmi.registry
|
||||
* java.rmi/sun.rmi.server
|
||||
* java.rmi/sun.rmi.transport
|
||||
* java.rmi/sun.rmi.transport.tcp
|
||||
* @build TestLibrary Receiver UseCodebaseOnly_Stub Foo Bar TestLoaderHandler
|
||||
* @run main/othervm UseCodebaseOnly
|
||||
*/
|
||||
|
||||
import java.net.*;
|
||||
import java.rmi.*;
|
||||
import java.rmi.server.*;
|
||||
|
||||
public class UseCodebaseOnly
|
||||
extends UnicastRemoteObject
|
||||
implements Receiver
|
||||
{
|
||||
|
||||
public UseCodebaseOnly() throws RemoteException {
|
||||
}
|
||||
|
||||
public void receive(Object obj) {
|
||||
System.err.println("+ receive(): received object " + obj);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.err.println("\nRegression test for bug 4174006\n");
|
||||
|
||||
System.setProperty("java.rmi.server.RMIClassLoaderSpi", "TestLoaderHandler");
|
||||
|
||||
URL localCodebase = null, remoteCodebase = null;
|
||||
try {
|
||||
remoteCodebase =
|
||||
TestLibrary.installClassInCodebase("Foo", "remote_codebase");
|
||||
localCodebase =
|
||||
TestLibrary.installClassInCodebase("Bar", "local_codebase");
|
||||
} catch (MalformedURLException e) {
|
||||
TestLibrary.bomb(e);
|
||||
}
|
||||
|
||||
TestLibrary.setProperty("java.rmi.server.useCodebaseOnly", "true");
|
||||
TestLibrary.setProperty( // set local codebase property
|
||||
"java.rmi.server.codebase", localCodebase.toString());
|
||||
|
||||
/*
|
||||
* Load Foo and Bar from non-RMI class loaders so that they won't be
|
||||
* already loaded by RMI class loaders in this VM (for whatever that's
|
||||
* worth), but with URLClassLoader so that they will be annotated
|
||||
* properly.
|
||||
*/
|
||||
System.err.println("Creating class loader for remote codebase " +
|
||||
remoteCodebase);
|
||||
ClassLoader remoteCodebaseLoader =
|
||||
URLClassLoader.newInstance(new URL[] { remoteCodebase });
|
||||
System.err.println("Creating class loader for local codebase " +
|
||||
localCodebase);
|
||||
ClassLoader localCodebaseLoader =
|
||||
URLClassLoader.newInstance(new URL[] { localCodebase });
|
||||
|
||||
System.err.println("Creating remote object.");
|
||||
UseCodebaseOnly obj = null;
|
||||
try {
|
||||
obj = new UseCodebaseOnly();
|
||||
} catch (RemoteException e) {
|
||||
TestLibrary.bomb(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Receiver stub = (Receiver) RemoteObject.toStub(obj);
|
||||
|
||||
/*
|
||||
* Pass an instance of Bar, the class in the local codebase.
|
||||
* This should succeed, because the server is allow to load
|
||||
* classes from the local codebase.
|
||||
*/
|
||||
System.err.println(
|
||||
"Passing class from local codebase (should succeed).");
|
||||
Class barClass = localCodebaseLoader.loadClass("Bar");
|
||||
Object barObj = barClass.newInstance();
|
||||
stub.receive(barObj);
|
||||
|
||||
/*
|
||||
* Pass an instance of Foo, the class in the remote codebase.
|
||||
* This should fail, because the server is not allowed to load
|
||||
* classes from other codebases besides the local codebase.
|
||||
*/
|
||||
System.err.println(
|
||||
"Passing class from remote codebase (should fail).");
|
||||
Class fooClass = remoteCodebaseLoader.loadClass("Foo");
|
||||
Object fooObj = fooClass.newInstance();
|
||||
try {
|
||||
stub.receive(fooObj);
|
||||
throw new RuntimeException("TEST FAILED: " +
|
||||
"class from remote codebase sucesssfully unmarshalled");
|
||||
} catch (RemoteException e) {
|
||||
/*
|
||||
* Verify that the failure was that the server couldn't
|
||||
* unmarshal the Foo class.
|
||||
*/
|
||||
if ((e instanceof ServerException) &&
|
||||
(e.detail instanceof UnmarshalException) &&
|
||||
(((RemoteException) e.detail).detail instanceof
|
||||
ClassNotFoundException) &&
|
||||
(((RemoteException) e.detail).detail.getMessage().equals(
|
||||
"Foo")))
|
||||
{
|
||||
System.err.println("TEST PASSED: ");
|
||||
e.printStackTrace();
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("TEST FAILED: ");
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("TEST FAILED: " + e.toString());
|
||||
} finally {
|
||||
try {
|
||||
UnicastRemoteObject.unexportObject(obj, true);
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
// Stub class generated by rmic, do not edit.
|
||||
// Contents subject to change without notice.
|
||||
|
||||
public final class UseCodebaseOnly_Stub
|
||||
extends java.rmi.server.RemoteStub
|
||||
implements Receiver, java.rmi.Remote
|
||||
{
|
||||
private static final java.rmi.server.Operation[] operations = {
|
||||
new java.rmi.server.Operation("void receive(java.lang.Object)")
|
||||
};
|
||||
|
||||
private static final long interfaceHash = -953299374608818732L;
|
||||
|
||||
private static final long serialVersionUID = 2;
|
||||
|
||||
private static boolean useNewInvoke;
|
||||
private static java.lang.reflect.Method $method_receive_0;
|
||||
|
||||
static {
|
||||
try {
|
||||
java.rmi.server.RemoteRef.class.getMethod("invoke",
|
||||
new java.lang.Class[] {
|
||||
java.rmi.Remote.class,
|
||||
java.lang.reflect.Method.class,
|
||||
java.lang.Object[].class,
|
||||
long.class
|
||||
});
|
||||
useNewInvoke = true;
|
||||
$method_receive_0 = Receiver.class.getMethod("receive", new java.lang.Class[] {java.lang.Object.class});
|
||||
} catch (java.lang.NoSuchMethodException e) {
|
||||
useNewInvoke = false;
|
||||
}
|
||||
}
|
||||
|
||||
// constructors
|
||||
public UseCodebaseOnly_Stub() {
|
||||
super();
|
||||
}
|
||||
public UseCodebaseOnly_Stub(java.rmi.server.RemoteRef ref) {
|
||||
super(ref);
|
||||
}
|
||||
|
||||
// methods from remote interfaces
|
||||
|
||||
// implementation of receive(Object)
|
||||
public void receive(java.lang.Object $param_Object_1)
|
||||
throws java.rmi.RemoteException
|
||||
{
|
||||
try {
|
||||
if (useNewInvoke) {
|
||||
ref.invoke(this, $method_receive_0, new java.lang.Object[] {$param_Object_1}, -578858472643205929L);
|
||||
} else {
|
||||
java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 0, interfaceHash);
|
||||
try {
|
||||
java.io.ObjectOutput out = call.getOutputStream();
|
||||
out.writeObject($param_Object_1);
|
||||
} catch (java.io.IOException e) {
|
||||
throw new java.rmi.MarshalException("error marshalling arguments", e);
|
||||
}
|
||||
ref.invoke(call);
|
||||
ref.done(call);
|
||||
}
|
||||
} catch (java.lang.RuntimeException e) {
|
||||
throw e;
|
||||
} catch (java.rmi.RemoteException e) {
|
||||
throw e;
|
||||
} catch (java.lang.Exception e) {
|
||||
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8001040
|
||||
* @summary Tests proper parsing and defaulting of the
|
||||
* "java.rmi.server.useCodebaseOnly" property.
|
||||
*
|
||||
* @modules java.rmi/sun.rmi.server:+open
|
||||
* @run main/othervm UseCodebaseOnlyDefault true
|
||||
* @run main/othervm -Djava.rmi.server.useCodebaseOnly=xyzzy UseCodebaseOnlyDefault true
|
||||
* @run main/othervm -Djava.rmi.server.useCodebaseOnly UseCodebaseOnlyDefault true
|
||||
* @run main/othervm -Djava.rmi.server.useCodebaseOnly=true UseCodebaseOnlyDefault true
|
||||
* @run main/othervm -Djava.rmi.server.useCodebaseOnly=false UseCodebaseOnlyDefault false
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import sun.rmi.server.MarshalInputStream;
|
||||
|
||||
/**
|
||||
* usage: UseCodebaseOnlyDefault expected
|
||||
*
|
||||
* 'expected' is the expected value of useCodebaseOnly, which
|
||||
* must be "true" or "false".
|
||||
*/
|
||||
public class UseCodebaseOnlyDefault {
|
||||
static final String USAGE = "usage: UseCodebaseOnlyDefault boolean";
|
||||
static final String PROPNAME = "java.rmi.server.useCodebaseOnly";
|
||||
|
||||
/**
|
||||
* Gets the actual useCodebaseOnly value by creating an instance
|
||||
* of MarshalInputStream and reflecting on the useCodebaseOnly field.
|
||||
*/
|
||||
static boolean getActualValue() throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject("foo");
|
||||
oos.close();
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
MarshalInputStream mis = new MarshalInputStream(bais);
|
||||
|
||||
Field f = MarshalInputStream.class.getDeclaredField("useCodebaseOnly");
|
||||
f.setAccessible(true);
|
||||
return f.getBoolean(mis);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 1) {
|
||||
throw new IllegalArgumentException(USAGE);
|
||||
}
|
||||
|
||||
boolean expected;
|
||||
if (args[0].equals("true")) {
|
||||
expected = true;
|
||||
} else if (args[0].equals("false")) {
|
||||
expected = false;
|
||||
} else {
|
||||
throw new IllegalArgumentException(USAGE);
|
||||
}
|
||||
System.out.println("expected = " + expected);
|
||||
|
||||
String prop = System.getProperty(PROPNAME);
|
||||
System.out.print("Property " + PROPNAME);
|
||||
if (prop == null) {
|
||||
System.out.println(" is not set");
|
||||
} else {
|
||||
System.out.println(" = '" + prop + "'");
|
||||
}
|
||||
|
||||
boolean actual = getActualValue();
|
||||
System.out.println("actual = " + actual);
|
||||
|
||||
if (expected != actual)
|
||||
throw new AssertionError("actual does not match expected value");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
public class Dummy {
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4137605
|
||||
* @summary When the RMIClassLoader.getClassAnnotation() is called with a
|
||||
* class loaded from any URLClassLoader instance (not just those created for
|
||||
* internal use by the RMI runtime), then it should return a String containing
|
||||
* a space-separated list of the class loader's path of URLs.
|
||||
* @author Peter Jones
|
||||
*
|
||||
* @library ../../../testlibrary
|
||||
* @modules java.rmi/sun.rmi.registry
|
||||
* java.rmi/sun.rmi.server
|
||||
* java.rmi/sun.rmi.transport
|
||||
* java.rmi/sun.rmi.transport.tcp
|
||||
* @build TestLibrary Dummy
|
||||
* @run main/othervm/timeout=120 UseGetURLs
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.rmi.*;
|
||||
import java.rmi.server.*;
|
||||
|
||||
public class UseGetURLs {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.err.println("\nRegression test for bug 4137605\n");
|
||||
|
||||
/*
|
||||
* Install dummy class in first codebase to be loaded from an
|
||||
* arbitrary URLClassLoader; the second codebase is used to make
|
||||
* the desired annotation more interesting (more than one element).
|
||||
*/
|
||||
URL codebase1 = null;
|
||||
URL codebase2 = null;
|
||||
try {
|
||||
codebase1 = TestLibrary.installClassInCodebase("Dummy",
|
||||
"codebase1");
|
||||
|
||||
File cb2file =
|
||||
new File(TestLibrary.getProperty("user.dir", "."),
|
||||
"codebase2");
|
||||
codebase2 = cb2file.toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
TestLibrary.bomb("failed to install test classes", e);
|
||||
}
|
||||
|
||||
try {
|
||||
/*
|
||||
* Create an arbitary URLClassLoader for the two codebases.
|
||||
*/
|
||||
ClassLoader loader = URLClassLoader.newInstance(
|
||||
new URL[] { codebase1, codebase2 });
|
||||
System.err.println(
|
||||
"URLs for class loader: " +
|
||||
Arrays.asList(((URLClassLoader) loader).getURLs()));
|
||||
System.err.println("Expecting annotation: \"" +
|
||||
codebase1 + " " + codebase2 + "\"");
|
||||
System.err.println("First URL:");
|
||||
dumpURL(codebase1);
|
||||
System.err.println("Second URL:");
|
||||
dumpURL(codebase2);
|
||||
|
||||
/*
|
||||
* Load dummy class from the loader, get the annotation string,
|
||||
* and verify that it is correct.
|
||||
*/
|
||||
Class cl = loader.loadClass("Dummy");
|
||||
String annotation = RMIClassLoader.getClassAnnotation(cl);
|
||||
System.err.println("Received annotation: \"" +
|
||||
annotation + "\"");
|
||||
|
||||
if (annotation == null) {
|
||||
throw new RuntimeException("annotation was null");
|
||||
}
|
||||
URL[] urls = pathToURLs(annotation);
|
||||
System.err.println(
|
||||
"URLs from annotation: " + Arrays.asList(urls));
|
||||
if (urls.length != 2) {
|
||||
throw new RuntimeException(
|
||||
"wrong number of elements in annotation");
|
||||
}
|
||||
if (!urls[0].equals(codebase1)) {
|
||||
System.err.println("First URL in annotation is incorrect:");
|
||||
dumpURL(urls[0]);
|
||||
throw new RuntimeException(
|
||||
"first URL in annotation is incorrect");
|
||||
}
|
||||
if (!urls[1].equals(codebase2)) {
|
||||
System.err.println("Second URL in annotation is incorrect:");
|
||||
dumpURL(urls[1]);
|
||||
throw new RuntimeException(
|
||||
"second URL in annotation is incorrect");
|
||||
}
|
||||
|
||||
System.err.println("TEST PASSED: annotation matched codebase");
|
||||
} catch (Exception e) {
|
||||
TestLibrary.bomb(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static URL[] pathToURLs(String path)
|
||||
throws MalformedURLException
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(path); // divide by spaces
|
||||
URL[] urls = new URL[st.countTokens()];
|
||||
for (int i = 0; st.hasMoreTokens(); i++) {
|
||||
urls[i] = new URL(st.nextToken());
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
|
||||
private static void dumpURL(URL u) {
|
||||
System.err.println("\tprotocol: " + u.getProtocol());
|
||||
System.err.println("\tauthority: " + u.getAuthority());
|
||||
System.err.println("\tuser info: " + u.getUserInfo());
|
||||
System.err.println("\thost: " + u.getHost());
|
||||
System.err.println("\tport: " + u.getPort());
|
||||
System.err.println("\tpath: " + u.getPath());
|
||||
System.err.println("\tfile: " + u.getFile());
|
||||
System.err.println("\tquery: " + u.getQuery());
|
||||
System.err.println("\tref: " + u.getRef());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue