diff --git a/src/com/esotericsoftware/reflectasm/AccessClassLoader.java b/src/com/esotericsoftware/reflectasm/AccessClassLoader.java index 59c4a8f..9ef0423 100644 --- a/src/com/esotericsoftware/reflectasm/AccessClassLoader.java +++ b/src/com/esotericsoftware/reflectasm/AccessClassLoader.java @@ -17,6 +17,7 @@ import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.security.ProtectionDomain; +import java.util.HashSet; import java.util.WeakHashMap; class AccessClassLoader extends ClassLoader { @@ -82,6 +83,19 @@ private AccessClassLoader (ClassLoader parent) { super(parent); } + HashSet locals = new HashSet(); + java.lang.Class loadClassLocal(String name) throws ClassNotFoundException { + if (locals.contains(name)) + return loadClass(name,false); + else + throw new ClassNotFoundException(); + } + Class defineClassLocal(String name, byte[] bytes) throws ClassFormatError { + locals.add(name); + return defineClass(name,bytes); + } + + protected java.lang.Class loadClass (String name, boolean resolve) throws ClassNotFoundException { // These classes come from the classloader that loaded AccessClassLoader. if (name.equals(FieldAccess.class.getName())) return FieldAccess.class; diff --git a/src/com/esotericsoftware/reflectasm/ConstructorAccess.java b/src/com/esotericsoftware/reflectasm/ConstructorAccess.java index 6364462..4bdc3c5 100644 --- a/src/com/esotericsoftware/reflectasm/ConstructorAccess.java +++ b/src/com/esotericsoftware/reflectasm/ConstructorAccess.java @@ -52,11 +52,11 @@ static public ConstructorAccess get (Class type) { AccessClassLoader loader = AccessClassLoader.get(type); try { - accessClass = loader.loadClass(accessClassName); + accessClass = loader.loadClassLocal(accessClassName); } catch (ClassNotFoundException ignored) { synchronized (loader) { try { - accessClass = loader.loadClass(accessClassName); + accessClass = loader.loadClassLocal(accessClassName); } catch (ClassNotFoundException ignored2) { String accessClassNameInternal = accessClassName.replace('.', '/'); String classNameInternal = className.replace('.', '/'); @@ -100,7 +100,7 @@ static public ConstructorAccess get (Class type) { insertNewInstanceInner(cw, classNameInternal, enclosingClassNameInternal); cw.visitEnd(); - accessClass = loader.defineClass(accessClassName, cw.toByteArray()); + accessClass = loader.defineClassLocal(accessClassName, cw.toByteArray()); } } } diff --git a/src/com/esotericsoftware/reflectasm/FieldAccess.java b/src/com/esotericsoftware/reflectasm/FieldAccess.java index 50f97e6..0226609 100644 --- a/src/com/esotericsoftware/reflectasm/FieldAccess.java +++ b/src/com/esotericsoftware/reflectasm/FieldAccess.java @@ -122,11 +122,11 @@ static public FieldAccess get (Class type) { AccessClassLoader loader = AccessClassLoader.get(type); try { - accessClass = loader.loadClass(accessClassName); + accessClass = loader.loadClassLocal(accessClassName); } catch (ClassNotFoundException ignored) { synchronized (loader) { try { - accessClass = loader.loadClass(accessClassName); + accessClass = loader.loadClassLocal(accessClassName); } catch (ClassNotFoundException ignored2) { String accessClassNameInternal = accessClassName.replace('.', '/'); String classNameInternal = className.replace('.', '/'); @@ -155,7 +155,7 @@ static public FieldAccess get (Class type) { insertSetPrimitive(cw, classNameInternal, fields, Type.CHAR_TYPE); insertGetString(cw, classNameInternal, fields); cw.visitEnd(); - accessClass = loader.defineClass(accessClassName, cw.toByteArray()); + accessClass = loader.defineClassLocal(accessClassName, cw.toByteArray()); } } } diff --git a/src/com/esotericsoftware/reflectasm/MethodAccess.java b/src/com/esotericsoftware/reflectasm/MethodAccess.java index fb40c20..51f67c4 100644 --- a/src/com/esotericsoftware/reflectasm/MethodAccess.java +++ b/src/com/esotericsoftware/reflectasm/MethodAccess.java @@ -108,11 +108,11 @@ static public MethodAccess get (Class type) { AccessClassLoader loader = AccessClassLoader.get(type); try { - accessClass = loader.loadClass(accessClassName); + accessClass = loader.loadClassLocal(accessClassName); } catch (ClassNotFoundException ignored) { synchronized (loader) { try { - accessClass = loader.loadClass(accessClassName); + accessClass = loader.loadClassLocal(accessClassName); } catch (ClassNotFoundException ignored2) { String accessClassNameInternal = accessClassName.replace('.', '/'); String classNameInternal = className.replace('.', '/'); @@ -272,7 +272,7 @@ else if (Modifier.isStatic(methods.get(i).getModifiers())) } cw.visitEnd(); byte[] data = cw.toByteArray(); - accessClass = loader.defineClass(accessClassName, data); + accessClass = loader.defineClassLocal(accessClassName, data); } } }