1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/*
* Copyright (c) 1998, 2014, 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 4149366
* @summary The class loader used to load classes for parameter types sent in
* an RMI call to an activatable object should delegate to the class loader
* that loaded the class of the activatable object itself, to maximize the
* likelihood of type compatibility between downloaded parameter types and
* supertypes shared with the activatable object.
* @author Peter Jones (much code taken from Ann Wollrath's activation tests)
*
* @library ../../../testlibrary
* @modules java.rmi/sun.rmi.registry
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* Foo FooReceiverImpl FooReceiverImpl_Stub Bar
* @run main/othervm/policy=security.policy/timeout=240 DownloadParameterClass
*/
import java.io.*;
import java.net.*;
import java.util.*;
import java.rmi.*;
import java.rmi.activation.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class DownloadParameterClass {
public interface FooReceiver extends Remote {
/*
* The interface can't actually declare that the method takes a
* Foo, because then Foo would have to be in the test's CLASSPATH,
* which might get propagated to the group VM's CLASSPATH, which
* would nullify the test (the Foo supertype must be loaded in the
* group VM only through the class loader that loaded the
* activatable object).
*/
public void receiveFoo(Object obj) throws RemoteException;
}
public static void main(String[] args) {
System.err.println("\nRegression test for bug 4149366\n");
/*
* Install classes to be seen by the activatable object's class
* loader in the "codebase1" subdirectory of working directory, and
* install the subtype to be downloaded into the activatable object
* into the "codebase2" subdirectory.
*/
URL codebase1 = null;
URL codebase2 = null;
try {
codebase1 = TestLibrary.installClassInCodebase("FooReceiverImpl", "codebase1");
TestLibrary.installClassInCodebase("FooReceiverImpl_Stub", "codebase1");
TestLibrary.installClassInCodebase("Foo", "codebase1");
codebase2 = TestLibrary.installClassInCodebase("Bar", "codebase2");
} catch (MalformedURLException e) {
TestLibrary.bomb("failed to install test classes", e);
}
TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
RMID rmid = null;
try {
RMID.removeLog();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
* allow security managers to be downloaded and installed
*/
Properties p = new Properties();
// this test must always set policies/managers in its
// activation groups
p.put("java.security.policy",
TestParams.defaultGroupPolicy);
p.put("java.security.manager",
TestParams.defaultSecurityManager);
/*
* Create and register descriptors for activatable object in a
* group other than this VM's group, so that another VM will be
* spawned with the object is activated.
*/
System.err.println("Creating descriptors");
ActivationGroupDesc groupDesc =
new ActivationGroupDesc(p, null);
ActivationGroupID groupID =
ActivationGroup.getSystem().registerGroup(groupDesc);
ActivationDesc objDesc =
new ActivationDesc(groupID, "FooReceiverImpl",
codebase1.toString(), null, false);
System.err.println("Registering descriptors");
FooReceiver obj = (FooReceiver) Activatable.register(objDesc);
/*
* Create an instance of the subtype to be downloaded by the
* activatable object. The codebase must be a path including
* "codebase1" as well as "codebase2" because the supertype
* must be visible here as well; the supertype cannot be
* installed in both codebases (like it would be in a typical
* setup) because of the trivial installation mechanism used
* below, and see the comment above for why it can't be in
* the test's CLASSPATH.
*/
Class subtype = RMIClassLoader.loadClass(
codebase2 + " " + codebase1, "Bar");
Object subtypeInstance = subtype.newInstance();
obj.receiveFoo(subtypeInstance);
System.err.println("\nTEST PASSED\n");
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
rmid.cleanup();
}
}
}
|