CreatePrivateActivatable.java revision 6244:bd84d0927a2e
1/* 2 * Copyright (c) 1999, 2008, 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 4164971 26 * @summary allow non-public activatable class and/or constructor 27 * @author Laird Dornin 28 * 29 * @library ../../../testlibrary 30 * @build TestLibrary RMID ActivateMe 31 * @run main/othervm/policy=security.policy/timeout=240 CreatePrivateActivatable 32 */ 33 34import java.io.*; 35import java.rmi.*; 36import java.rmi.server.*; 37import java.rmi.activation.*; 38import sun.rmi.server.ActivatableRef; 39import java.lang.reflect.*; 40import java.util.Properties; 41 42/** 43 * Test creates a private inner class Activatable object with a 44 * private constructor and makes sure that the object can be 45 * activated. 46 */ 47public class CreatePrivateActivatable 48{ 49 private static class PrivateActivatable extends Activatable 50 implements ActivateMe, Runnable 51 { 52 private PrivateActivatable(ActivationID id, MarshalledObject obj) 53 throws ActivationException, RemoteException 54 { 55 super(id, 0); 56 } 57 58 public void ping() 59 {} 60 61 /** 62 * Spawns a thread to deactivate the object. 63 */ 64 public void shutdown() throws Exception 65 { 66 (new Thread(this, "CreatePrivateActivatable$PrivateActivatable")).start(); 67 } 68 69 /** 70 * Thread to deactivate object. First attempts to make object 71 * inactive (via the inactive method). If that fails (the 72 * object may still have pending/executing calls), then 73 * unexport the object forcibly. 74 */ 75 public void run() { 76 ActivationLibrary.deactivate(this, getID()); 77 } 78 } 79 80 public static void main(String[] args) { 81 /* 82 * The following line is required with the JDK 1.2 VM so that the 83 * VM can exit gracefully when this test completes. Otherwise, the 84 * conservative garbage collector will find a handle to the server 85 * object on the native stack and not clear the weak reference to 86 * it in the RMI runtime's object table. 87 */ 88 Object dummy = new Object(); 89 RMID rmid = null; 90 ActivateMe obj; 91 92 System.err.println("\nRegression test for bug 4164971\n"); 93 System.err.println("java.security.policy = " + 94 System.getProperty("java.security.policy", "no policy")); 95 96 CreatePrivateActivatable server; 97 try { 98 TestLibrary.suggestSecurityManager(TestParams.defaultSecurityManager); 99 100 // start an rmid. 101 RMID.removeLog(); 102 rmid = RMID.createRMID(); 103 rmid.start(); 104 105 /* Cause activation groups to have a security policy that will 106 * allow security managers to be downloaded and installed 107 */ 108 Properties p = new Properties(); 109 // this test must always set policies/managers in its 110 // activation groups 111 p.put("java.security.policy", 112 TestParams.defaultGroupPolicy); 113 p.put("java.security.manager", 114 TestParams.defaultSecurityManager); 115 116 /* 117 * Activate an object by registering its object 118 * descriptor and invoking a method on the 119 * stub returned from the register call. 120 */ 121 ActivationGroupDesc groupDesc = 122 new ActivationGroupDesc(p, null); 123 ActivationSystem system = ActivationGroup.getSystem(); 124 ActivationGroupID groupID = system.registerGroup(groupDesc); 125 126 System.err.println("Creating descriptor"); 127 ActivationDesc desc = 128 new ActivationDesc(groupID, 129 "CreatePrivateActivatable$PrivateActivatable", 130 null, null); 131 132 System.err.println("Registering descriptor"); 133 obj = (ActivateMe) Activatable.register(desc); 134 135 /* 136 * Loop a bunch of times to force activator to 137 * spawn VMs (groups) 138 */ 139 System.err.println("Activate object via method call"); 140 obj.ping(); 141 142 /* 143 * Clean up object too. 144 */ 145 System.err.println("Deactivate object via method call"); 146 obj.shutdown(); 147 148 System.err.println("\nsuccess: CreatePrivateActivatable test passed "); 149 150 } catch (Exception e) { 151 if (e instanceof java.security.PrivilegedActionException) { 152 e = ((java.security.PrivilegedActionException)e).getException(); 153 } 154 TestLibrary.bomb("\nfailure: unexpected exception " + 155 e.getClass().getName(), e); 156 157 } finally { 158 ActivationLibrary.rmidCleanup(rmid); 159 obj = null; 160 } 161 } 162} 163