Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/Activatable/checkImplClassLoader/CheckImplClassLoader.java
38826 views
/*1* Copyright (c) 2000, 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 428954425* @summary ActivationGroupImpl.newInstance does not set context classloader for impl26* @author Laird Dornin; code borrowed from Ann Wollrath27*28* @library ../../../testlibrary29* @build TestLibrary RMID30* MyRMI ActivatableImpl ActivatableImpl ActivatableImpl_Stub31* @run main/othervm/policy=security.policy/timeout=150 CheckImplClassLoader32*/3334import java.io.*;35import java.rmi.*;36import java.rmi.server.*;37import java.rmi.activation.*;38import java.net.URL;3940/**41* sun.rmi.server.ActivationGroupImpl.newInstance() needs to set the42* context class loader when it constructs the implementation class of43* an Activatable object. It needs to set the ccl to be the class44* loader of the implementation class.45*46* Test creates an Activatable object whose impl is loaded outside of47* CLASSPATH. The impls constructor checks to make sure that the48* correct context class loader has been set when the constructor is49* invoked.50*/51public class CheckImplClassLoader {5253private static Object dummy = new Object();54private static MyRMI myRMI = null;55private static ActivationGroup group = null;5657public static void main(String args[]) {58/*59* The following line is required with the JDK 1.2 VM because60* of gc hocus pocus that may no longer be needed with an61* exact vm (hotspot).62*/63Object dummy1 = new Object();64RMID rmid = null;6566System.err.println("\nRegression test for bug/rfe 4289544\n");6768try {6970URL implcb = TestLibrary.installClassInCodebase("ActivatableImpl",71"implcb");72TestLibrary.installClassInCodebase("ActivatableImpl_Stub",73"implcb");74TestLibrary.suggestSecurityManager(75TestParams.defaultSecurityManager);7677RMID.removeLog();78rmid = RMID.createRMID();79rmid.start();8081System.err.println("Create activation group in this VM");82ActivationGroupDesc groupDesc =83new ActivationGroupDesc(null, null);84ActivationSystem system = ActivationGroup.getSystem();85ActivationGroupID groupID = system.registerGroup(groupDesc);86group = ActivationGroup.createGroup(groupID, groupDesc, 0);8788ActivationDesc desc = new ActivationDesc("ActivatableImpl",89implcb.toString(), null);90myRMI = (MyRMI) Activatable.register(desc);9192System.err.println("Checking that impl has correct " +93"context class loader");94if (!myRMI.classLoaderOk()) {95TestLibrary.bomb("incorrect context class loader for " +96"activation constructor");97}9899System.err.println("Deactivate object via method call");100myRMI.shutdown();101102System.err.println("\nsuccess: CheckImplClassLoader test passed ");103104} catch (Exception e) {105TestLibrary.bomb("\nfailure: unexpected exception ", e);106} finally {107try {108Thread.sleep(4000);109} catch (InterruptedException e) {110}111112myRMI = null;113System.err.println("rmid shut down");114ActivationLibrary.rmidCleanup(rmid);115TestLibrary.unexport(group);116}117}118}119120121