7186111: fix bugs in java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup

Reviewed-by: smarks, jgish
This commit is contained in:
Darryl Mocek 2012-07-27 16:53:15 -07:00
parent 37f0895031
commit 1625e2019e
4 changed files with 40 additions and 38 deletions

View File

@ -45,30 +45,23 @@ import java.rmi.registry.*;
import java.util.Properties; import java.util.Properties;
class Callback extends UnicastRemoteObject implements CallbackInterface { class Callback extends UnicastRemoteObject implements CallbackInterface {
public int num_deactivated = 0;
public static int num_deactivated = 0; public Callback() throws RemoteException { super(); }
public Callback() throws RemoteException { super(); } public synchronized void inc() throws RemoteException {
num_deactivated++;
public void inc() throws RemoteException { }
incNumDeactivated();
}
public synchronized int getNumDeactivated() throws RemoteException {
return(num_deactivated);
}
public synchronized void incNumDeactivated() {
num_deactivated++;
}
public synchronized int getNumDeactivated() throws RemoteException {
return num_deactivated;
}
} }
public class UnregisterGroup public class UnregisterGroup
extends Activatable extends Activatable
implements ActivateMe, Runnable implements ActivateMe, Runnable
{ {
private static Exception exception = null; private static Exception exception = null;
private static String error = null; private static String error = null;
private static boolean done = false; private static boolean done = false;
@ -104,36 +97,47 @@ public class UnregisterGroup
} }
/** /**
* Thread to deactivate object. First attempts to make object * Thread to deactivate object. Get the callback object from the registry,
* inactive (via the inactive method). If that fails (the * call inc() on it, and finally call deactivate(). The call to
* object may still have pending/executing calls), then * deactivate() causes this JVM to be destroyed, so anything following
* unexport the object forcibly. * might not be executed.
*/ */
public void run() { public void run() {
String regPortStr = System.getProperty("unregisterGroup.port");
int regPort = -1;
ActivationLibrary.deactivate(this, getID()); if (regPortStr != null) {
System.err.println("\tActivationLibrary.deactivate returned"); regPort = Integer.parseInt(regPortStr);
}
try { try {
CallbackInterface cobj = CallbackInterface cobj =
(CallbackInterface)Naming.lookup("//:" + registryPort + "/Callback"); (CallbackInterface)Naming.lookup("//:" + regPort + "/Callback");
cobj.inc(); cobj.inc();
System.err.println("cobj.inc called and returned ok");
} catch (Exception e) { } catch (Exception e) {
System.err.println("cobj.inc exception"); System.err.println("cobj.inc exception");
e.printStackTrace(); e.printStackTrace();
} }
ActivationLibrary.deactivate(this, getID());
System.err.println("\tActivationLibrary.deactivate returned");
} }
public static void main(String[] args) { public static void main(String[] args) throws RemoteException {
Registry registry;
System.err.println("\nRegression test for bug 4134233\n"); System.err.println("\nRegression test for bug 4134233\n");
TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
RMID rmid = null; RMID rmid = null;
// Create registry and export callback object so they're
// available to the objects that are activated below.
// TODO: see if we can use RMID's registry instead of
// creating one here.
Registry registry = TestLibrary.createRegistryOnUnusedPort();
registryPort = TestLibrary.getRegistryPort(registry);
Callback robj = new Callback();
registry.rebind("Callback", robj);
try { try {
RMID.removeLog(); RMID.removeLog();
rmid = RMID.createRMID(); rmid = RMID.createRMID();
@ -149,8 +153,7 @@ public class UnregisterGroup
TestParams.defaultGroupPolicy); TestParams.defaultGroupPolicy);
p.put("java.security.manager", p.put("java.security.manager",
TestParams.defaultSecurityManager); TestParams.defaultSecurityManager);
p.put("unregisterGroup.port", Integer.toString(registryPort));
//final int NUM_OBJECTS = 10;
Thread t = new Thread() { Thread t = new Thread() {
public void run () { public void run () {
@ -219,8 +222,6 @@ public class UnregisterGroup
} else { } else {
System.err.println("Test passed"); System.err.println("Test passed");
} }
} catch (Exception e) { } catch (Exception e) {
TestLibrary.bomb("test failed", e); TestLibrary.bomb("test failed", e);
} finally { } finally {
@ -233,13 +234,6 @@ public class UnregisterGroup
// Wait for the object deactivation to take place first // Wait for the object deactivation to take place first
try { try {
// create reg and export callback object
registry = TestLibrary.createRegistryOnUnusedPort();
registryPort = TestLibrary.getRegistryPort(registry);
Callback robj = new Callback();
registry.bind("Callback", robj);
//get the callback object //get the callback object
int maxwait=30; int maxwait=30;
int nd = robj.getNumDeactivated(); int nd = robj.getNumDeactivated();

View File

@ -7,4 +7,5 @@ grant {
// test needs to communicate with the activation system // test needs to communicate with the activation system
permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.util.PropertyPermission "unregisterGroup.port", "read";
}; };

View File

@ -1,4 +1,5 @@
grant { grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default"; permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission com.sun.rmi.rmid.ExecOptionPermission "-DunregisterGroup.port=*";
}; };

View File

@ -33,4 +33,10 @@ grant {
// test needs to export rmid and communicate with objects on arbitrary ports // test needs to export rmid and communicate with objects on arbitrary ports
permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
// required for test to get the registry port
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport";
permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp";
}; };