changeset 5896:da1867780fc9

8006435: Improvements in JMX Summary: Improvements in JMX Reviewed-by: dfuchs, skoivu
author dsamersoff
date Mon, 25 Feb 2013 20:06:22 +0400
parents cf93d3828aa8
children 09c9880d963c
files src/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java src/share/classes/sun/reflect/misc/ReflectUtil.java
diffstat 2 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java	Fri Feb 22 15:14:25 2013 +0400
+++ b/src/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java	Mon Feb 25 20:06:22 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * 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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -213,7 +213,6 @@
 
         Object moi;
 
-
         // ------------------------------
         // ------------------------------
         Constructor<?> cons = findConstructor(theClass, null);
@@ -224,6 +223,7 @@
         // Instantiate the new object
         try {
             ReflectUtil.checkPackageAccess(theClass);
+            ReflectUtil.ensureClassAccess(theClass);
             moi= cons.newInstance();
         } catch (InvocationTargetException e) {
             // Wrap the exception.
@@ -270,7 +270,6 @@
         checkMBeanPermission(theClass, null, null, "instantiate");
 
         // Instantiate the new object
-
         // ------------------------------
         // ------------------------------
         final Class<?>[] tab;
@@ -300,6 +299,7 @@
         }
         try {
             ReflectUtil.checkPackageAccess(theClass);
+            ReflectUtil.ensureClassAccess(theClass);
             moi = cons.newInstance(params);
         }
         catch (NoSuchMethodError error) {
--- a/src/share/classes/sun/reflect/misc/ReflectUtil.java	Fri Feb 22 15:14:25 2013 +0400
+++ b/src/share/classes/sun/reflect/misc/ReflectUtil.java	Mon Feb 25 20:06:22 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2013 Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -46,6 +46,14 @@
         return cls.newInstance();
     }
 
+    public 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");
+        }
+    }
     /*
      * Reflection.ensureMemberAccess is overly-restrictive
      * due to a bug. We awkwardly work around it for now.