提交 5eb426e8 编写于 作者: J jbachorik

8008585: Better JMX data handling

Reviewed-by: alanb, dfuchs, jfdenise, skoivu, sjiang
上级 f47e2e27
......@@ -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('-', '_');
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册