src/share/classes/sun/reflect/misc/ReflectUtil.java

Print this page

        

*** 142,147 **** --- 142,177 ---- } catch (SecurityException e) { return false; } return true; } + + /** + * Returns true if package access check is needed for reflective + * access from a class loader 'from' to classes or members in + * a class defined by class loader 'to'. This method returns true + * if 'from' is not the same as or an ancestor of 'to'. All code + * in a system domain are granted with all permission and so this + * method returns false if 'from' class loader is a class loader + * loading system classes. On the other hand, if a class loader + * attempts to access system domain classes, it requires package + * access check and this method will return true. + */ + public static boolean needsPackageAccessCheck(ClassLoader from, ClassLoader to) { + if (from == null || from == to) + return false; + + if (to == null) + return true; + + // If from class loader is in the to's class loader's delegation chain. + // no need for package access check. + ClassLoader acl = to; + do { + acl = acl.getParent(); + if (from == acl) { + return false; + } + } while (acl != null); + return true; + } }