Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/Activatable/createPrivateActivable/CreatePrivateActivatable.java
38829 views
/*1* Copyright (c) 1999, 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 416497125* @summary allow non-public activatable class and/or constructor26* @author Laird Dornin27*28* @library ../../../testlibrary29* @build TestLibrary RMID ActivateMe30* @run main/othervm/policy=security.policy/timeout=240 CreatePrivateActivatable31*/3233import java.io.*;34import java.rmi.*;35import java.rmi.server.*;36import java.rmi.activation.*;37import sun.rmi.server.ActivatableRef;38import java.lang.reflect.*;39import java.util.Properties;4041/**42* Test creates a private inner class Activatable object with a43* private constructor and makes sure that the object can be44* activated.45*/46public class CreatePrivateActivatable47{48private static class PrivateActivatable extends Activatable49implements ActivateMe, Runnable50{51private PrivateActivatable(ActivationID id, MarshalledObject obj)52throws ActivationException, RemoteException53{54super(id, 0);55}5657public void ping()58{}5960/**61* Spawns a thread to deactivate the object.62*/63public void shutdown() throws Exception64{65(new Thread(this, "CreatePrivateActivatable$PrivateActivatable")).start();66}6768/**69* Thread to deactivate object. First attempts to make object70* inactive (via the inactive method). If that fails (the71* object may still have pending/executing calls), then72* unexport the object forcibly.73*/74public void run() {75ActivationLibrary.deactivate(this, getID());76}77}7879public static void main(String[] args) {80/*81* The following line is required with the JDK 1.2 VM so that the82* VM can exit gracefully when this test completes. Otherwise, the83* conservative garbage collector will find a handle to the server84* object on the native stack and not clear the weak reference to85* it in the RMI runtime's object table.86*/87Object dummy = new Object();88RMID rmid = null;89ActivateMe obj;9091System.err.println("\nRegression test for bug 4164971\n");92System.err.println("java.security.policy = " +93System.getProperty("java.security.policy", "no policy"));9495CreatePrivateActivatable server;96try {97TestLibrary.suggestSecurityManager(TestParams.defaultSecurityManager);9899// start an rmid.100RMID.removeLog();101rmid = RMID.createRMID();102rmid.start();103104/* Cause activation groups to have a security policy that will105* allow security managers to be downloaded and installed106*/107Properties p = new Properties();108// this test must always set policies/managers in its109// activation groups110p.put("java.security.policy",111TestParams.defaultGroupPolicy);112p.put("java.security.manager",113TestParams.defaultSecurityManager);114115/*116* Activate an object by registering its object117* descriptor and invoking a method on the118* stub returned from the register call.119*/120ActivationGroupDesc groupDesc =121new ActivationGroupDesc(p, null);122ActivationSystem system = ActivationGroup.getSystem();123ActivationGroupID groupID = system.registerGroup(groupDesc);124125System.err.println("Creating descriptor");126ActivationDesc desc =127new ActivationDesc(groupID,128"CreatePrivateActivatable$PrivateActivatable",129null, null);130131System.err.println("Registering descriptor");132obj = (ActivateMe) Activatable.register(desc);133134/*135* Loop a bunch of times to force activator to136* spawn VMs (groups)137*/138System.err.println("Activate object via method call");139obj.ping();140141/*142* Clean up object too.143*/144System.err.println("Deactivate object via method call");145obj.shutdown();146147System.err.println("\nsuccess: CreatePrivateActivatable test passed ");148149} catch (Exception e) {150if (e instanceof java.security.PrivilegedActionException) {151e = ((java.security.PrivilegedActionException)e).getException();152}153TestLibrary.bomb("\nfailure: unexpected exception " +154e.getClass().getName(), e);155156} finally {157ActivationLibrary.rmidCleanup(rmid);158obj = null;159}160}161}162163164