Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/Activatable/downloadParameterClass/DownloadParameterClass.java
38918 views
/*1* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 414936625* @summary The class loader used to load classes for parameter types sent in26* an RMI call to an activatable object should delegate to the class loader27* that loaded the class of the activatable object itself, to maximize the28* likelihood of type compatibility between downloaded parameter types and29* supertypes shared with the activatable object.30* @author Peter Jones (much code taken from Ann Wollrath's activation tests)31*32* @library ../../../testlibrary33* @build TestLibrary RMID ActivationLibrary34* Foo FooReceiverImpl FooReceiverImpl_Stub Bar35* @run main/othervm/policy=security.policy/timeout=240 DownloadParameterClass36*/3738import java.io.*;39import java.net.*;40import java.util.*;41import java.rmi.*;42import java.rmi.activation.*;43import java.rmi.server.*;44import java.rmi.registry.*;4546public class DownloadParameterClass {4748public interface FooReceiver extends Remote {4950/*51* The interface can't actually declare that the method takes a52* Foo, because then Foo would have to be in the test's CLASSPATH,53* which might get propagated to the group VM's CLASSPATH, which54* would nullify the test (the Foo supertype must be loaded in the55* group VM only through the class loader that loaded the56* activatable object).57*/58public void receiveFoo(Object obj) throws RemoteException;59}6061public static void main(String[] args) {6263System.err.println("\nRegression test for bug 4149366\n");6465/*66* Install classes to be seen by the activatable object's class67* loader in the "codebase1" subdirectory of working directory, and68* install the subtype to be downloaded into the activatable object69* into the "codebase2" subdirectory.70*/71URL codebase1 = null;72URL codebase2 = null;73try {74codebase1 = TestLibrary.installClassInCodebase("FooReceiverImpl", "codebase1");75TestLibrary.installClassInCodebase("FooReceiverImpl_Stub", "codebase1");76TestLibrary.installClassInCodebase("Foo", "codebase1");77codebase2 = TestLibrary.installClassInCodebase("Bar", "codebase2");78} catch (MalformedURLException e) {79TestLibrary.bomb("failed to install test classes", e);80}8182TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");8384RMID rmid = null;8586try {87RMID.removeLog();88rmid = RMID.createRMID();89rmid.start();9091/* Cause activation groups to have a security policy that will92* allow security managers to be downloaded and installed93*/94Properties p = new Properties();95// this test must always set policies/managers in its96// activation groups97p.put("java.security.policy",98TestParams.defaultGroupPolicy);99p.put("java.security.manager",100TestParams.defaultSecurityManager);101102/*103* Create and register descriptors for activatable object in a104* group other than this VM's group, so that another VM will be105* spawned with the object is activated.106*/107System.err.println("Creating descriptors");108ActivationGroupDesc groupDesc =109new ActivationGroupDesc(p, null);110ActivationGroupID groupID =111ActivationGroup.getSystem().registerGroup(groupDesc);112ActivationDesc objDesc =113new ActivationDesc(groupID, "FooReceiverImpl",114codebase1.toString(), null, false);115116System.err.println("Registering descriptors");117FooReceiver obj = (FooReceiver) Activatable.register(objDesc);118119/*120* Create an instance of the subtype to be downloaded by the121* activatable object. The codebase must be a path including122* "codebase1" as well as "codebase2" because the supertype123* must be visible here as well; the supertype cannot be124* installed in both codebases (like it would be in a typical125* setup) because of the trivial installation mechanism used126* below, and see the comment above for why it can't be in127* the test's CLASSPATH.128*/129Class subtype = RMIClassLoader.loadClass(130codebase2 + " " + codebase1, "Bar");131Object subtypeInstance = subtype.newInstance();132133obj.receiveFoo(subtypeInstance);134135System.err.println("\nTEST PASSED\n");136137} catch (Exception e) {138TestLibrary.bomb("test failed", e);139} finally {140ActivationLibrary.rmidCleanup(rmid);141}142}143}144145146