< prev index next >

test/java/rmi/server/UnicastRemoteObject/unexportObject/UnexportLeak.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2012, 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  */


  32  * @modules java.rmi/sun.rmi.registry
  33  *          java.rmi/sun.rmi.server
  34  *          java.rmi/sun.rmi.transport
  35  *          java.rmi/sun.rmi.transport.tcp
  36  * @build TestLibrary UnexportLeak_Stub Ping
  37  * @run main/othervm UnexportLeak
  38  */
  39 
  40 import java.lang.ref.*;
  41 import java.rmi.*;
  42 import java.rmi.server.*;
  43 import java.rmi.registry.*;
  44 
  45 public class UnexportLeak implements Ping {
  46     public void ping() {
  47     }
  48 
  49     public static void main(String[] args) {
  50         try {
  51             System.err.println("\nRegression test for bug 4331349\n");
  52             Registry registry = TestLibrary.createRegistryOnUnusedPort();
  53             int registryPort = TestLibrary.getRegistryPort(registry);
  54             Remote obj = new UnexportLeak();
  55             WeakReference wr = new WeakReference(obj);
  56             UnicastRemoteObject.exportObject(obj);
  57             LocateRegistry.getRegistry(registryPort).rebind("UnexportLeak", obj);
  58             UnicastRemoteObject.unexportObject(obj, true);
  59             obj = null;
  60             flushRefs();
  61             if (wr.get() != null) {
  62                 System.err.println("FAILED: unexported object not collected");
  63                 throw new RuntimeException(
  64                     "FAILED: unexported object not collected");
  65             } else {
  66                 System.err.println("PASSED: unexported object collected");
  67             }
  68         } catch (RemoteException e) {
  69             System.err.println(
  70                 "FAILED: RemoteException encountered: " + e.getMessage());
  71             e.printStackTrace();
  72             throw new RuntimeException("FAILED: RemoteException encountered");
   1 /*
   2  * Copyright (c) 2000, 2016, 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  */


  32  * @modules java.rmi/sun.rmi.registry
  33  *          java.rmi/sun.rmi.server
  34  *          java.rmi/sun.rmi.transport
  35  *          java.rmi/sun.rmi.transport.tcp
  36  * @build TestLibrary UnexportLeak_Stub Ping
  37  * @run main/othervm UnexportLeak
  38  */
  39 
  40 import java.lang.ref.*;
  41 import java.rmi.*;
  42 import java.rmi.server.*;
  43 import java.rmi.registry.*;
  44 
  45 public class UnexportLeak implements Ping {
  46     public void ping() {
  47     }
  48 
  49     public static void main(String[] args) {
  50         try {
  51             System.err.println("\nRegression test for bug 4331349\n");
  52             Registry registry = TestLibrary.createRegistryOnEphemeralPort();
  53             int registryPort = TestLibrary.getRegistryPort(registry);
  54             Remote obj = new UnexportLeak();
  55             WeakReference wr = new WeakReference(obj);
  56             UnicastRemoteObject.exportObject(obj);
  57             LocateRegistry.getRegistry(registryPort).rebind("UnexportLeak", obj);
  58             UnicastRemoteObject.unexportObject(obj, true);
  59             obj = null;
  60             flushRefs();
  61             if (wr.get() != null) {
  62                 System.err.println("FAILED: unexported object not collected");
  63                 throw new RuntimeException(
  64                     "FAILED: unexported object not collected");
  65             } else {
  66                 System.err.println("PASSED: unexported object collected");
  67             }
  68         } catch (RemoteException e) {
  69             System.err.println(
  70                 "FAILED: RemoteException encountered: " + e.getMessage());
  71             e.printStackTrace();
  72             throw new RuntimeException("FAILED: RemoteException encountered");
< prev index next >