8008585: Better JMX data handling

Reviewed-by: alanb, dfuchs, jfdenise, skoivu, sjiang
This commit is contained in:
Jaroslav Bachorik 2013-03-14 14:42:12 +01:00
parent 9e0c698e00
commit 69718bb834

View File

@ -39,6 +39,7 @@ import java.security.PrivilegedAction;
import com.sun.jmx.remote.util.ClassLogger;
import com.sun.jmx.remote.util.EnvHelp;
import sun.reflect.misc.ReflectUtil;
/**
@ -412,10 +413,10 @@ public class JMXConnectorFactory {
}
static <T> T getProvider(JMXServiceURL serviceURL,
Map<String, Object> environment,
final Map<String, Object> environment,
String providerClassName,
Class<T> targetInterface,
ClassLoader loader)
final ClassLoader loader)
throws IOException {
final String protocol = serviceURL.getProtocol();
@ -425,11 +426,14 @@ public class JMXConnectorFactory {
T instance = null;
if (pkgs != null) {
environment.put(PROTOCOL_PROVIDER_CLASS_LOADER, loader);
instance =
getProvider(protocol, pkgs, loader, providerClassName,
targetInterface);
if (instance != null) {
boolean needsWrap = (loader != instance.getClass().getClassLoader());
environment.put(PROTOCOL_PROVIDER_CLASS_LOADER, needsWrap ? wrap(loader) : loader);
}
}
return instance;
@ -442,6 +446,21 @@ public class JMXConnectorFactory {
return serviceLoader.iterator();
}
private static ClassLoader wrap(final ClassLoader parent) {
return parent != null ? AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
@Override
public ClassLoader run() {
return new ClassLoader(parent) {
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
ReflectUtil.checkPackageAccess(name);
return super.loadClass(name, resolve);
}
};
}
}) : null;
}
private static JMXConnector getConnectorAsService(ClassLoader loader,
JMXServiceURL url,
Map<String, ?> map)
@ -552,5 +571,4 @@ public class JMXConnectorFactory {
private static String protocol2package(String protocol) {
return protocol.replace('+', '.').replace('-', '_');
}
}