Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/Activatable/nonExistentActivatable/NonExistentActivatable.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 411529625* @summary synopsis: NoSuchObjectException not thrown for non-existent26* activatable objects27* @author Ann Wollrath28*29* @library ../../../testlibrary30* @build TestLibrary RMID ActivationLibrary31* ActivateMe NonExistentActivatable_Stub32* @run main/othervm/policy=security.policy/timeout=240 NonExistentActivatable33*/3435import java.io.*;36import java.rmi.*;37import java.rmi.activation.*;38import java.rmi.server.*;39import java.rmi.registry.*;40import java.util.Properties;4142public class NonExistentActivatable43extends Activatable44implements ActivateMe, Runnable45{4647public NonExistentActivatable(ActivationID id, MarshalledObject obj)48throws ActivationException, RemoteException49{50super(id, 0);51}5253public void ping()54{}5556public void unregister() throws Exception {57super.unregister(super.getID());58}5960/**61* Spawns a thread to deactivate the object.62*/63public void shutdown() throws Exception64{65(new Thread(this,"NonExistentActivatable")).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()75{76ActivationLibrary.deactivate(this, getID());77}7879public static void main(String[] args) {8081System.out.println("\nRegression test for bug 4115331\n");8283TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");8485RMID rmid = null;8687try {88RMID.removeLog();89rmid = RMID.createRMID();90rmid.start();9192/* Cause activation groups to have a security policy that will93* allow security managers to be downloaded and installed94*/95Properties p = new Properties();96// this test must always set policies/managers in its97// activation groups98p.put("java.security.policy",99TestParams.defaultGroupPolicy);100p.put("java.security.manager",101TestParams.defaultSecurityManager);102103System.err.println("Create activation group in this VM");104ActivationGroupDesc groupDesc =105new ActivationGroupDesc(p, null);106ActivationSystem system = ActivationGroup.getSystem();107ActivationGroupID groupID = system.registerGroup(groupDesc);108ActivationGroup.createGroup(groupID, groupDesc, 0);109110System.err.println("Creating descriptor");111ActivationDesc desc =112new ActivationDesc("NonExistentActivatable", null, null);113114System.err.println("Registering descriptor");115ActivateMe obj = (ActivateMe) Activatable.register(desc);116117System.err.println("Activate object via method call");118obj.ping();119120System.err.println("Unregister object");121obj.unregister();122123System.err.println("Make object inactive");124obj.shutdown();125126System.err.println("Reactivate object");127try {128obj.ping();129} catch (NoSuchObjectException e) {130System.err.println("Test succeeded: " +131"NoSuchObjectException caught");132return;133} catch (Exception e) {134TestLibrary.bomb("Test failed: exception other than NoSuchObjectException",135e);136}137138} catch (Exception e) {139TestLibrary.bomb("test failed", e);140} finally {141ActivationLibrary.rmidCleanup(rmid);142}143}144}145146147