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