1 /* 2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 4289544 26 * @summary ActivationGroupImpl.newInstance does not set context classloader for impl 27 * @author Laird Dornin; code borrowed from Ann Wollrath 28 * 29 * @library ../../../testlibrary 30 * @build TestLibrary RMID 31 * MyRMI ActivatableImpl ActivatableImpl ActivatableImpl_Stub 32 * @run main/othervm/policy=security.policy/timeout=150 CheckImplClassLoader 33 */ 34 35 import java.io.*; 36 import java.rmi.*; 37 import java.rmi.server.*; 38 import java.rmi.activation.*; 39 import java.net.URL; 40 41 /** 42 * sun.rmi.server.ActivationGroupImpl.newInstance() needs to set the 43 * context class loader when it constructs the implementation class of 44 * an Activatable object. It needs to set the ccl to be the class 45 * loader of the implementation class. 46 * 47 * Test creates an Activatable object whose impl is loaded outside of 48 * CLASSPATH. The impls constructor checks to make sure that the 49 * correct context class loader has been set when the constructor is 50 * invoked. 51 */ 52 public class CheckImplClassLoader { 53 54 private static Object dummy = new Object(); 55 private static MyRMI myRMI = null; 56 private static ActivationGroup group = null; 57 58 public static void main(String args[]) { 59 /* 60 * The following line is required with the JDK 1.2 VM because 61 * of gc hocus pocus that may no longer be needed with an 62 * exact vm (hotspot). 63 */ 64 Object dummy1 = new Object(); 65 RMID rmid = null; 66 67 System.err.println("\nRegression test for bug/rfe 4289544\n"); 68 69 try { 70 71 URL implcb = TestLibrary.installClassInCodebase("ActivatableImpl", 72 "implcb"); 73 TestLibrary.installClassInCodebase("ActivatableImpl_Stub", 74 "implcb"); 75 TestLibrary.suggestSecurityManager( 76 TestParams.defaultSecurityManager); 77 78 RMID.removeLog(); 79 rmid = RMID.createRMID(); 80 rmid.start(); 81 82 System.err.println("Create activation group in this VM"); 83 ActivationGroupDesc groupDesc = 84 new ActivationGroupDesc(null, null); 85 ActivationSystem system = ActivationGroup.getSystem(); 86 ActivationGroupID groupID = system.registerGroup(groupDesc); 87 group = ActivationGroup.createGroup(groupID, groupDesc, 0); 88 89 ActivationDesc desc = new ActivationDesc("ActivatableImpl", 90 implcb.toString(), null); 91 myRMI = (MyRMI) Activatable.register(desc); 92 93 System.err.println("Checking that impl has correct " + 94 "context class loader"); 95 if (!myRMI.classLoaderOk()) { 96 TestLibrary.bomb("incorrect context class loader for " + 97 "activation constructor"); 98 } 99 100 System.err.println("Deactivate object via method call"); 101 myRMI.shutdown(); 102 103 System.err.println("\nsuccess: CheckImplClassLoader test passed "); 104 105 } catch (Exception e) { 106 TestLibrary.bomb("\nfailure: unexpected exception ", e); 107 } finally { 108 try { 109 Thread.sleep(4000); 110 } catch (InterruptedException e) { 111 } 112 113 myRMI = null; 114 System.err.println("rmid shut down"); 115 ActivationLibrary.rmidCleanup(rmid); 116 TestLibrary.unexport(group); 117 } 118 } 119 }