J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1998-1999 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* @test |
| 25 | * @bug 4128620 |
| 26 | * |
| 27 | * @summary synopsis: NoSuchMethodError should be elucidated |
| 28 | * |
| 29 | * @author Laird Dornin |
| 30 | * |
| 31 | * @library ../../../testlibrary |
| 32 | * @build TestLibrary RMID |
| 33 | * @build ActivateMe ElucidateNoSuchMethod ElucidateNoSuchMethod_Stub |
| 34 | * @run main/othervm/policy=security.policy/timeout=240 ElucidateNoSuchMethod |
| 35 | */ |
| 36 | |
| 37 | import java.io.*; |
| 38 | import java.rmi.*; |
| 39 | import java.rmi.activation.*; |
| 40 | import java.rmi.server.*; |
| 41 | import java.rmi.registry.*; |
| 42 | import java.util.Properties; |
| 43 | |
| 44 | public class ElucidateNoSuchMethod |
| 45 | extends Activatable |
| 46 | implements ActivateMe, Runnable |
| 47 | { |
| 48 | |
| 49 | /** |
| 50 | * provide a constructor that alllows this object to be made |
| 51 | * activatable, or at least registered. |
| 52 | */ |
| 53 | ElucidateNoSuchMethod(ActivationID id, int port) |
| 54 | throws RemoteException |
| 55 | { |
| 56 | super(id, port); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * dont provide an activation constructor so that we get a no such |
| 61 | * method error. |
| 62 | */ |
| 63 | |
| 64 | public void ping() {} |
| 65 | |
| 66 | /** |
| 67 | * Spawns a thread to deactivate the object. |
| 68 | */ |
| 69 | public void shutdown() throws Exception { |
| 70 | (new Thread(this,"ElucidateNoSuchMethod")).start(); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Thread to deactivate object. First attempts to make object |
| 75 | * inactive (via the inactive method). If that fails (the |
| 76 | * object may still have pending/executing calls), then |
| 77 | * unexport the object forcibly. |
| 78 | */ |
| 79 | public void run() { |
| 80 | ActivationLibrary.deactivate(this, getID()); |
| 81 | } |
| 82 | |
| 83 | public static void main(String[] args) { |
| 84 | |
| 85 | System.out.println("\nRegression test for 4128620 \n"); |
| 86 | |
| 87 | TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); |
| 88 | |
| 89 | RMID rmid = null; |
| 90 | |
| 91 | try { |
| 92 | RMID.removeLog(); |
| 93 | rmid = RMID.createRMID(); |
| 94 | rmid.start(); |
| 95 | |
| 96 | /* Cause activation groups to have a security policy that will |
| 97 | * allow security managers to be downloaded and installed |
| 98 | */ |
| 99 | Properties p = new Properties(); |
| 100 | // this test must always set policies/managers in its |
| 101 | // activation groups |
| 102 | p.put("java.security.policy", |
| 103 | TestParams.defaultGroupPolicy); |
| 104 | p.put("java.security.manager", |
| 105 | TestParams.defaultSecurityManager); |
| 106 | |
| 107 | System.err.println("Create activation group in this VM"); |
| 108 | ActivationGroupDesc groupDesc = |
| 109 | new ActivationGroupDesc(p, null); |
| 110 | ActivationSystem system = ActivationGroup.getSystem(); |
| 111 | ActivationGroupID groupID = system.registerGroup(groupDesc); |
| 112 | ActivationGroup.createGroup(groupID, groupDesc, 0); |
| 113 | |
| 114 | System.err.println("Creating descriptor"); |
| 115 | ActivationDesc desc = |
| 116 | new ActivationDesc("ElucidateNoSuchMethod", null, null); |
| 117 | |
| 118 | System.err.println("Registering descriptor"); |
| 119 | ActivateMe obj = (ActivateMe) Activatable.register(desc); |
| 120 | |
| 121 | System.err.println("Activate object via method call"); |
| 122 | |
| 123 | try { |
| 124 | obj.ping(); |
| 125 | } catch (ActivateFailedException afe) { |
| 126 | ActivationException a = (ActivationException) afe.detail; |
| 127 | |
| 128 | if (((a.detail instanceof NoSuchMethodException) || |
| 129 | (a.detail instanceof NoSuchMethodError)) && |
| 130 | (a.getMessage().indexOf |
| 131 | ("must provide an activation constructor") > -1)) { |
| 132 | System.err.println("\ntest passed for 4128620\n"); |
| 133 | } else { |
| 134 | TestLibrary.bomb("test failed", afe); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | } catch (Exception e) { |
| 139 | TestLibrary.bomb("test failed", e); |
| 140 | } finally { |
| 141 | ActivationLibrary.rmidCleanup(rmid); |
| 142 | } |
| 143 | } |
| 144 | } |