Index: xbean-reflect/src/main/java/org/apache/xbean/recipe/ReflectionUtil.java =================================================================== --- xbean-reflect/src/main/java/org/apache/xbean/recipe/ReflectionUtil.java (revision 1538849) +++ xbean-reflect/src/main/java/org/apache/xbean/recipe/ReflectionUtil.java (revision 1538850) @@ -25,8 +25,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -1011,12 +1009,7 @@ } private static void setAccessible(final AccessibleObject accessibleObject) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - accessibleObject.setAccessible(true); - return null; - } - }); + accessibleObject.setAccessible(true); } private static String toParameterList(Class[] parameterTypes) { Index: xbean-classpath/src/main/java/org/apache/xbean/classpath/SunURLClassPath.java =================================================================== --- xbean-classpath/src/main/java/org/apache/xbean/classpath/SunURLClassPath.java (revision 1538849) +++ xbean-classpath/src/main/java/org/apache/xbean/classpath/SunURLClassPath.java (revision 1538850) @@ -24,11 +24,7 @@ public abstract class SunURLClassPath implements ClassPath { public static ClassLoader getContextClassLoader() { - return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return Thread.currentThread().getContextClassLoader(); - } - }); + return Thread.currentThread().getContextClassLoader(); } private java.lang.reflect.Field ucpField; Index: xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java =================================================================== --- xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java (revision 1539052) +++ xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java (revision 1539053) @@ -20,12 +20,7 @@ import java.io.File; import java.net.URL; import java.net.URI; -import java.security.AccessControlContext; -import java.security.AccessController; import java.security.CodeSource; -import java.security.PrivilegedAction; -import java.security.PrivilegedExceptionAction; -import java.security.PrivilegedActionException; import java.security.cert.Certificate; import java.util.Collection; import java.util.Enumeration; @@ -49,7 +44,6 @@ private static final URL[] EMPTY_URLS = new URL[0]; private final UrlResourceFinder resourceFinder = new UrlResourceFinder(); - private final AccessControlContext acc; /** * Creates a JarFileClassLoader that is a child of the system class loader. @@ -58,7 +52,6 @@ */ public JarFileClassLoader(String name, URL[] urls) { super(name, EMPTY_URLS); - this.acc = AccessController.getContext(); addURLs(urls); } @@ -70,13 +63,11 @@ */ public JarFileClassLoader(String name, URL[] urls, ClassLoader parent) { super(name, EMPTY_URLS, parent); - this.acc = AccessController.getContext(); addURLs(urls); } public JarFileClassLoader(String name, URL[] urls, ClassLoader parent, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) { super(name, EMPTY_URLS, parent, inverseClassLoading, hiddenClasses, nonOverridableClasses); - this.acc = AccessController.getContext(); addURLs(urls); } @@ -88,19 +79,16 @@ */ public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents) { super(name, EMPTY_URLS, parents); - this.acc = AccessController.getContext(); addURLs(urls); } public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, Collection hiddenClasses, Collection nonOverridableClasses) { super(name, EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses); - this.acc = AccessController.getContext(); addURLs(urls); } public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) { super(name, EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses); - this.acc = AccessController.getContext(); addURLs(urls); } @@ -115,12 +103,7 @@ * {@inheritDoc} */ public void addURL(final URL url) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - resourceFinder.addUrl(url); - return null; - } - }, acc); + resourceFinder.addUrl(url); } /** @@ -128,12 +111,7 @@ * @param urls the URLs to add */ protected void addURLs(final URL[] urls) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - resourceFinder.addUrls(urls); - return null; - } - }, acc); + resourceFinder.addUrls(urls); } /** @@ -148,11 +126,7 @@ * {@inheritDoc} */ public URL findResource(final String resourceName) { - return (URL) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return resourceFinder.findResource(resourceName); - } - }, acc); + return resourceFinder.findResource(resourceName); } /** @@ -164,11 +138,7 @@ Enumeration parentResources = super.findResources(resourceName); // get the classes from my urls - Enumeration myResources = (Enumeration) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return resourceFinder.findResources(resourceName); - } - }, acc); + Enumeration myResources = resourceFinder.findResources(resourceName); // join the two together Enumeration resources = new UnionEnumeration(parentResources, myResources); @@ -196,11 +166,7 @@ } // get a resource handle to the library - ResourceHandle resourceHandle = (ResourceHandle) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return resourceFinder.getResource(resourceName); - } - }, acc); + ResourceHandle resourceHandle = resourceFinder.getResource(resourceName); if (resourceHandle == null) { return null; @@ -220,62 +186,53 @@ * {@inheritDoc} */ protected Class findClass(final String className) throws ClassNotFoundException { - try { - return (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws ClassNotFoundException { - // first think check if we are allowed to define the package - SecurityManager securityManager = System.getSecurityManager(); - if (securityManager != null) { - String packageName; - int packageEnd = className.lastIndexOf('.'); - if (packageEnd >= 0) { - packageName = className.substring(0, packageEnd); - securityManager.checkPackageDefinition(packageName); - } - } + // first think check if we are allowed to define the package + SecurityManager securityManager = System.getSecurityManager(); + if (securityManager != null) { + String packageName; + int packageEnd = className.lastIndexOf('.'); + if (packageEnd >= 0) { + packageName = className.substring(0, packageEnd); + securityManager.checkPackageDefinition(packageName); + } + } + // convert the class name to a file name + String resourceName = className.replace('.', '/') + ".class"; - // convert the class name to a file name - String resourceName = className.replace('.', '/') + ".class"; + // find the class file resource + ResourceHandle resourceHandle = resourceFinder.getResource(resourceName); + if (resourceHandle == null) { + throw new ClassNotFoundException(className); + } - // find the class file resource - ResourceHandle resourceHandle = resourceFinder.getResource(resourceName); - if (resourceHandle == null) { - throw new ClassNotFoundException(className); - } + byte[] bytes; + Manifest manifest; + try { + // get the bytes from the class file + bytes = resourceHandle.getBytes(); + + // get the manifest for defining the packages + manifest = resourceHandle.getManifest(); + } catch (IOException e) { + throw new ClassNotFoundException(className, e); + } - byte[] bytes; - Manifest manifest; - try { - // get the bytes from the class file - bytes = resourceHandle.getBytes(); + // get the certificates for the code source + Certificate[] certificates = resourceHandle.getCertificates(); + + // the code source url is used to define the package and as the security context for the class + URL codeSourceUrl = resourceHandle.getCodeSourceUrl(); - // get the manifest for defining the packages - manifest = resourceHandle.getManifest(); - } catch (IOException e) { - throw new ClassNotFoundException(className, e); - } + // define the package (required for security) + definePackage(className, codeSourceUrl, manifest); - // get the certificates for the code source - Certificate[] certificates = resourceHandle.getCertificates(); - - // the code source url is used to define the package and as the security context for the class - URL codeSourceUrl = resourceHandle.getCodeSourceUrl(); - - // define the package (required for security) - definePackage(className, codeSourceUrl, manifest); - - // this is the security context of the class - CodeSource codeSource = new CodeSource(codeSourceUrl, certificates); - - // load the class into the vm - Class clazz = defineClass(className, bytes, 0, bytes.length, codeSource); - return clazz; - } - }, acc); - } catch (PrivilegedActionException e) { - throw (ClassNotFoundException) e.getException(); - } + // this is the security context of the class + CodeSource codeSource = new CodeSource(codeSourceUrl, certificates); + + // load the class into the vm + Class clazz = defineClass(className, bytes, 0, bytes.length, codeSource); + return clazz; } private void definePackage(String className, URL jarUrl, Manifest manifest) { Index: xbean-classpath/src/main/java/org/apache/xbean/classpath/TomcatClassPath.java =================================================================== --- xbean-classpath/src/main/java/org/apache/xbean/classpath/TomcatClassPath.java (revision 1539055) +++ xbean-classpath/src/main/java/org/apache/xbean/classpath/TomcatClassPath.java (revision 1539056) @@ -20,8 +20,6 @@ import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; -import java.security.AccessController; -import java.security.PrivilegedAction; public class TomcatClassPath extends SunURLClassPath { @@ -140,36 +138,19 @@ * @return URLClassLoader.addURL method instance */ private Method getAddURLMethod() throws Exception { - return (Method) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Method method = null; - try { - Class clazz = URLClassLoader.class; - method = clazz.getDeclaredMethod("addURL", new Class[]{URL.class}); - method.setAccessible(true); - return method; - } catch (Exception e2) { - e2.printStackTrace(); - } - return method; - } - }); + Method method = null; + Class clazz = URLClassLoader.class; + method = clazz.getDeclaredMethod("addURL", new Class[]{URL.class}); + method.setAccessible(true); + return method; } private Method getAddRepositoryMethod() throws Exception { - return (Method) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Method method = null; - try { - Class clazz = getClassLoader().getClass(); - method = clazz.getDeclaredMethod("addRepository", new Class[]{String.class}); - method.setAccessible(true); - return method; - } catch (Exception e2) { - throw (IllegalStateException) new IllegalStateException("Unable to find or access the addRepository method in StandardClassLoader").initCause(e2); - } - } - }); + Method method = null; + Class clazz = getClassLoader().getClass(); + method = clazz.getDeclaredMethod("addRepository", new Class[]{String.class}); + method.setAccessible(true); + return method; } } Index: xbean-classpath/src/main/java/org/apache/xbean/classpath/SunURLClassPath.java =================================================================== --- xbean-classpath/src/main/java/org/apache/xbean/classpath/SunURLClassPath.java (revision 1539055) +++ xbean-classpath/src/main/java/org/apache/xbean/classpath/SunURLClassPath.java (revision 1539056) @@ -19,10 +19,9 @@ import java.io.File; import java.net.URL; import java.net.URLClassLoader; -import java.security.AccessController; -import java.security.PrivilegedAction; public abstract class SunURLClassPath implements ClassPath { + public static ClassLoader getContextClassLoader() { return Thread.currentThread().getContextClassLoader(); } @@ -64,20 +63,9 @@ private java.lang.reflect.Field getUcpField() throws Exception { if (ucpField == null) { // Add them to the URLClassLoader's classpath - ucpField = (java.lang.reflect.Field) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - java.lang.reflect.Field ucp = null; - try { - ucp = URLClassLoader.class.getDeclaredField("ucp"); - ucp.setAccessible(true); - } catch (Exception e2) { - e2.printStackTrace(); - } - return ucp; - } - }); + ucpField = URLClassLoader.class.getDeclaredField("ucp"); + ucpField.setAccessible(true); } - return ucpField; }