diff options
author | kkhan <kkhan@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2006-08-16 10:38:17 +0000 |
---|---|---|
committer | kkhan <kkhan@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2006-08-16 10:38:17 +0000 |
commit | 81ef701676102f088eb97330a11474093a8ed016 (patch) | |
tree | 971694e1a0ae28b2ae4c9f39561c0b7f606a5739 | |
parent | 7a730c89d7e58896d381dff5800c32a424c44b6b (diff) | |
download | javassist-81ef701676102f088eb97330a11474093a8ed016.tar.gz javassist-81ef701676102f088eb97330a11474093a8ed016.zip |
Class.gerDeclaredMethod() needs to happen in a privileged block
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@311 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r-- | src/main/javassist/ClassPool.java | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java index 1fb0082a..5db629f4 100644 --- a/src/main/javassist/ClassPool.java +++ b/src/main/javassist/ClassPool.java @@ -21,6 +21,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.security.ProtectionDomain; import java.util.Hashtable; import java.util.Iterator; @@ -67,17 +70,22 @@ public class ClassPool { static { try { - Class cl = Class.forName("java.lang.ClassLoader"); - defineClass1 = cl.getDeclaredMethod("defineClass", - new Class[] { String.class, byte[].class, - int.class, int.class }); - - defineClass2 = cl.getDeclaredMethod("defineClass", - new Class[] { String.class, byte[].class, - int.class, int.class, ProtectionDomain.class }); + AccessController.doPrivileged(new PrivilegedExceptionAction(){ + public Object run() throws Exception{ + Class cl = Class.forName("java.lang.ClassLoader"); + defineClass1 = cl.getDeclaredMethod("defineClass", + new Class[] { String.class, byte[].class, + int.class, int.class }); + + defineClass2 = cl.getDeclaredMethod("defineClass", + new Class[] { String.class, byte[].class, + int.class, int.class, ProtectionDomain.class }); + return null; + } + }); } - catch (Exception e) { - throw new RuntimeException("cannot initialize ClassPool"); + catch (PrivilegedActionException pae) { + throw new RuntimeException("cannot initialize ClassPool", pae.getException()); } } |