# HG changeset patch # User andrew # Date 1365784460 -3600 # Node ID e0803f17f824df0bbedf0dd03aa06938389b1b9f # Parent dfa1c658a62a54dbcfa02e96c51af21a3cc71907 8006435: Improvements in JMX Summary: Improvements in JMX Reviewed-by: dfuchs, skoivu diff --git a/src/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java b/src/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java --- jdk/src/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java +++ jdk/src/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2007, 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 = null; - // ------------------------------ // ------------------------------ 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; @@ -301,6 +300,7 @@ } try { ReflectUtil.checkPackageAccess(theClass); + ReflectUtil.ensureClassAccess(theClass); moi = cons.newInstance(params); } catch (NoSuchMethodError error) { diff --git a/src/share/classes/sun/reflect/misc/ReflectUtil.java b/src/share/classes/sun/reflect/misc/ReflectUtil.java --- jdk/src/share/classes/sun/reflect/misc/ReflectUtil.java +++ jdk/src/share/classes/sun/reflect/misc/ReflectUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, 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.