...
Code Block | ||
---|---|---|
| ||
import java.beans.Beans; class SafeInstantiate { public static <T> T create(Class<T> c) { try { SafeClassLoader scl = new SafeClassLoader(); ClassLoader cl = scl.getClass().getClassLoader(); Object b = Beans.instantiate(cl, c.getName()); return c.cast(b.getClass()); } catch(ExceptionThrowable et) { /* forward to handler */ } return null; } public static void main(String[] args) { TaintedClass ac1 = new TaintedClass(); // unprivileged Class<?> c = ac1.getClass(); TaintedClass ac2 = (TaintedClass)SafeInstantiate.create(c); // loads with the specified classloader } } |
...