diff --git a/src/java.base/share/classes/module-info.java b/src/java.base/share/classes/module-info.java
index 5a44adeb294..c3bcbed4e3b 100644
--- a/src/java.base/share/classes/module-info.java
+++ b/src/java.base/share/classes/module-info.java
@@ -315,7 +315,6 @@ module java.base {
exports sun.reflect.misc to
java.desktop,
java.management,
- java.management.rmi,
java.rmi,
java.sql.rowset;
exports sun.security.internal.interfaces to
diff --git a/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnectionImpl.java b/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnectionImpl.java
index cb318dc65b2..9c0b3d56214 100644
--- a/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnectionImpl.java
+++ b/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnectionImpl.java
@@ -29,24 +29,17 @@ import java.io.IOException;
import java.rmi.MarshalledObject;
import java.rmi.UnmarshalException;
import java.rmi.server.Unreferenced;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.security.Permission;
-import java.security.Permissions;
-import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.security.ProtectionDomain;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.CompletionException;
import javax.management.*;
import javax.management.remote.JMXServerErrorException;
import javax.management.remote.NotificationResult;
import javax.security.auth.Subject;
-import sun.reflect.misc.ReflectUtil;
import static javax.management.remote.rmi.RMIConnector.Util.cast;
import com.sun.jmx.remote.internal.ServerCommunicatorAdmin;
@@ -94,7 +87,6 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
* RMIServerImpl
. Can be null, equivalent to an
* empty map.
*/
- @SuppressWarnings("removal")
public RMIConnectionImpl(RMIServerImpl rmiServer,
String connectionId,
ClassLoader defaultClassLoader,
@@ -111,54 +103,13 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
this.mbeanServer = rmiServer.getMBeanServer();
final ClassLoader dcl = defaultClassLoader;
-
- ClassLoaderRepository repository = AccessController.doPrivileged(
- new PrivilegedAction() {
- public ClassLoaderRepository run() {
- return mbeanServer.getClassLoaderRepository();
- }
- },
- withPermissions(new MBeanPermission("*", "getClassLoaderRepository"))
- );
- this.classLoaderWithRepository = AccessController.doPrivileged(
- new PrivilegedAction() {
- public ClassLoaderWithRepository run() {
- return new ClassLoaderWithRepository(
- repository,
- dcl);
- }
- },
- withPermissions(new RuntimePermission("createClassLoader"))
- );
-
- this.defaultContextClassLoader =
- AccessController.doPrivileged(
- new PrivilegedAction() {
- @Override
- public ClassLoader run() {
- return new CombinedClassLoader(Thread.currentThread().getContextClassLoader(),
- dcl);
- }
- });
-
- serverCommunicatorAdmin = new
- RMIServerCommunicatorAdmin(EnvHelp.getServerConnectionTimeout(env));
-
+ ClassLoaderRepository repository = mbeanServer.getClassLoaderRepository();
+ classLoaderWithRepository = new ClassLoaderWithRepository(repository, dcl);
+ defaultContextClassLoader = new CombinedClassLoader(Thread.currentThread().getContextClassLoader(), dcl);
+ serverCommunicatorAdmin = new RMIServerCommunicatorAdmin(EnvHelp.getServerConnectionTimeout(env));
this.env = env;
}
- @SuppressWarnings("removal")
- private static AccessControlContext withPermissions(Permission ... perms){
- Permissions col = new Permissions();
-
- for (Permission thePerm : perms ) {
- col.add(thePerm);
- }
-
- final ProtectionDomain pd = new ProtectionDomain(null, col);
- return new AccessControlContext( new ProtectionDomain[] { pd });
- }
-
private synchronized ServerNotifForwarder getServerNotifFwd() {
// Lazily created when first use. Mainly when
// addNotificationListener is first called.
@@ -397,7 +348,7 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
+", unwrapping params with MBean extended ClassLoader.");
values = nullIsEmpty(unwrap(params,
- getClassLoader(loaderName),
+ mbeanServer.getClassLoader(loaderName),
defaultClassLoader,
Object[].class,delegationSubject));
@@ -1249,7 +1200,6 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
}
}
- @SuppressWarnings("removal")
public NotificationResult fetchNotifications(long clientSequenceNumber,
int maxNotifications,
long timeout)
@@ -1274,19 +1224,22 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
+ "returns null to force the client to stop fetching");
return null;
}
- final long csn = clientSequenceNumber;
- final int mn = maxNotifications;
- final long t = timeout;
- PrivilegedAction action =
- new PrivilegedAction() {
- public NotificationResult run() {
- return getServerNotifFwd().fetchNotifs(csn, t, mn);
- }
- };
+
if (subject == null) {
- return action.run();
+ return getServerNotifFwd().fetchNotifs(clientSequenceNumber, timeout, maxNotifications);
} else {
- return Subject.doAs(subject, action);
+ try {
+ return Subject.callAs(subject, () -> getServerNotifFwd().fetchNotifs(clientSequenceNumber, timeout, maxNotifications));
+ } catch (CompletionException ce) {
+ Throwable thr = ce.getCause();
+ if (thr instanceof SecurityException se) {
+ throw se;
+ } else if (thr instanceof IOException ioe) {
+ throw ioe;
+ } else {
+ throw new RuntimeException(thr);
+ }
+ }
}
} finally {
serverCommunicatorAdmin.rspOutgoing();
@@ -1311,25 +1264,6 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
// private classes
//------------------------------------------------------------------------
- private class PrivilegedOperation
- implements PrivilegedExceptionAction