Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/ElucidateNoSuchMethod.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 412862025* @summary synopsis: NoSuchMethodError should be elucidated26* @author Laird Dornin27*28* @library ../../../testlibrary29* @build TestLibrary RMID ActivateMe ElucidateNoSuchMethod_Stub30* @run main/othervm/policy=security.policy/timeout=240 ElucidateNoSuchMethod31*/3233import java.io.*;34import java.rmi.*;35import java.rmi.activation.*;36import java.rmi.server.*;37import java.rmi.registry.*;38import java.util.Properties;3940public class ElucidateNoSuchMethod41extends Activatable42implements ActivateMe, Runnable43{4445/**46* provide a constructor that alllows this object to be made47* activatable, or at least registered.48*/49ElucidateNoSuchMethod(ActivationID id, int port)50throws RemoteException51{52super(id, port);53}5455/**56* dont provide an activation constructor so that we get a no such57* method error.58*/5960public void ping() {}6162/**63* Spawns a thread to deactivate the object.64*/65public void shutdown() throws Exception {66(new Thread(this,"ElucidateNoSuchMethod")).start();67}6869/**70* Thread to deactivate object. First attempts to make object71* inactive (via the inactive method). If that fails (the72* object may still have pending/executing calls), then73* unexport the object forcibly.74*/75public void run() {76ActivationLibrary.deactivate(this, getID());77}7879public static void main(String[] args) {8081System.out.println("\nRegression test for 4128620 \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("ElucidateNoSuchMethod", null, null);113114System.err.println("Registering descriptor");115ActivateMe obj = (ActivateMe) Activatable.register(desc);116117System.err.println("Activate object via method call");118119try {120obj.ping();121} catch (ActivateFailedException afe) {122ActivationException a = (ActivationException) afe.detail;123124if (((a.detail instanceof NoSuchMethodException) ||125(a.detail instanceof NoSuchMethodError)) &&126(a.getMessage().indexOf127("must provide an activation constructor") > -1)) {128System.err.println("\ntest passed for 4128620\n");129} else {130TestLibrary.bomb("test failed", afe);131}132}133134} catch (Exception e) {135TestLibrary.bomb("test failed", e);136} finally {137ActivationLibrary.rmidCleanup(rmid);138}139}140}141142143