提交 9b7766f3 编写于 作者: D dsamersoff

8006435: Improvements in JMX

Summary: Improvements in JMX
Reviewed-by: dfuchs, skoivu, alanb, mchung
上级 d53bbf63
/* /*
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,6 +32,7 @@ import java.io.IOException; ...@@ -32,6 +32,7 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.security.Permission; import java.security.Permission;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -213,7 +214,6 @@ public class MBeanInstantiator { ...@@ -213,7 +214,6 @@ public class MBeanInstantiator {
Object moi; Object moi;
// ------------------------------ // ------------------------------
// ------------------------------ // ------------------------------
Constructor<?> cons = findConstructor(theClass, null); Constructor<?> cons = findConstructor(theClass, null);
...@@ -224,6 +224,7 @@ public class MBeanInstantiator { ...@@ -224,6 +224,7 @@ public class MBeanInstantiator {
// Instantiate the new object // Instantiate the new object
try { try {
ReflectUtil.checkPackageAccess(theClass); ReflectUtil.checkPackageAccess(theClass);
ensureClassAccess(theClass);
moi= cons.newInstance(); moi= cons.newInstance();
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
// Wrap the exception. // Wrap the exception.
...@@ -270,7 +271,6 @@ public class MBeanInstantiator { ...@@ -270,7 +271,6 @@ public class MBeanInstantiator {
checkMBeanPermission(theClass, null, null, "instantiate"); checkMBeanPermission(theClass, null, null, "instantiate");
// Instantiate the new object // Instantiate the new object
// ------------------------------ // ------------------------------
// ------------------------------ // ------------------------------
final Class<?>[] tab; final Class<?>[] tab;
...@@ -300,6 +300,7 @@ public class MBeanInstantiator { ...@@ -300,6 +300,7 @@ public class MBeanInstantiator {
} }
try { try {
ReflectUtil.checkPackageAccess(theClass); ReflectUtil.checkPackageAccess(theClass);
ensureClassAccess(theClass);
moi = cons.newInstance(params); moi = cons.newInstance(params);
} }
catch (NoSuchMethodError error) { catch (NoSuchMethodError error) {
...@@ -741,4 +742,13 @@ public class MBeanInstantiator { ...@@ -741,4 +742,13 @@ public class MBeanInstantiator {
sm.checkPermission(perm); sm.checkPermission(perm);
} }
} }
private static void ensureClassAccess(Class clazz)
throws IllegalAccessException
{
int mod = clazz.getModifiers();
if (!Modifier.isPublic(mod)) {
throw new IllegalAccessException("Class is not public and can't be instantiated");
}
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册