diff options
author | aclement <aclement> | 2008-05-27 18:51:06 +0000 |
---|---|---|
committer | aclement <aclement> | 2008-05-27 18:51:06 +0000 |
commit | 261516ac8697ee5604ed9928b59abb73d4dc24d0 (patch) | |
tree | 9067496078a5faf0075651d05352fbc3e06f9611 /weaver5/java5-src | |
parent | 4fef2b08d0278b67d5957d10510cd746bff3e334 (diff) | |
download | aspectj-261516ac8697ee5604ed9928b59abb73d4dc24d0.tar.gz aspectj-261516ac8697ee5604ed9928b59abb73d4dc24d0.zip |
210470: preventing weaver leaks: use a weak classloader ref
Diffstat (limited to 'weaver5/java5-src')
-rw-r--r-- | weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java | 18 | ||||
-rw-r--r-- | weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java | 6 |
2 files changed, 15 insertions, 9 deletions
diff --git a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java index 7b8bca505..c5f0b62f3 100644 --- a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java +++ b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java @@ -31,6 +31,7 @@ import org.aspectj.apache.bcel.util.Repository; import org.aspectj.weaver.AnnotationX; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.UnresolvedType; +import org.aspectj.weaver.WeakClassLoaderReference; import org.aspectj.weaver.World; /** @@ -40,7 +41,7 @@ import org.aspectj.weaver.World; public class Java15AnnotationFinder implements AnnotationFinder, ArgNameFinder { private Repository bcelRepository; - private ClassLoader classLoader; + private WeakClassLoaderReference classLoaderRef; private World world; // must have no-arg constructor for reflective construction @@ -50,8 +51,8 @@ public class Java15AnnotationFinder implements AnnotationFinder, ArgNameFinder { public void setClassLoader(ClassLoader aLoader) { // TODO: No easy way to ask the world factory for the right kind of repository so // default to the safe one! (pr160674) - this.bcelRepository = new NonCachingClassLoaderRepository(aLoader); - this.classLoader = aLoader; + this.classLoaderRef = new WeakClassLoaderReference(aLoader); + this.bcelRepository = new NonCachingClassLoaderRepository(classLoaderRef); } public void setWorld(World aWorld) { @@ -63,7 +64,8 @@ public class Java15AnnotationFinder implements AnnotationFinder, ArgNameFinder { */ public Object getAnnotation(ResolvedType annotationType, Object onObject) { try { - Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) Class.forName(annotationType.getName(),false,classLoader); + Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) Class.forName(annotationType.getName(), false, + getClassLoader()); if (onObject.getClass().isAnnotationPresent(annotationClass)) { return onObject.getClass().getAnnotation(annotationClass); } @@ -75,7 +77,7 @@ public class Java15AnnotationFinder implements AnnotationFinder, ArgNameFinder { public Object getAnnotationFromClass(ResolvedType annotationType, Class aClass) { try { - Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) Class.forName(annotationType.getName(),false,classLoader); + Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) Class.forName(annotationType.getName(),false,getClassLoader()); if (aClass.isAnnotationPresent(annotationClass)) { return aClass.getAnnotation(annotationClass); } @@ -89,7 +91,7 @@ public class Java15AnnotationFinder implements AnnotationFinder, ArgNameFinder { if (!(aMember instanceof AccessibleObject)) return null; AccessibleObject ao = (AccessibleObject) aMember; try { - Class annotationClass = Class.forName(annotationType.getName(),false,classLoader); + Class annotationClass = Class.forName(annotationType.getName(),false,getClassLoader()); if (ao.isAnnotationPresent(annotationClass)) { return ao.getAnnotation(annotationClass); } @@ -99,6 +101,10 @@ public class Java15AnnotationFinder implements AnnotationFinder, ArgNameFinder { return null; } + private ClassLoader getClassLoader() { + return classLoaderRef.getClassLoader(); + } + public AnnotationX getAnnotationOfType(UnresolvedType ofType,Member onMember) { if (!(onMember instanceof AccessibleObject)) return null; // here we really want both the runtime visible AND the class visible annotations diff --git a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java index 629a0f441..4774d6beb 100644 --- a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java +++ b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java @@ -66,7 +66,7 @@ public class Java15ReflectionBasedReferenceTypeDelegate extends myType = AjTypeSystem.getAjType(aClass); annotationFinder = new Java15AnnotationFinder(); argNameFinder = annotationFinder; - annotationFinder.setClassLoader(this.classLoader); + annotationFinder.setClassLoader(this.classLoaderReference.getClassLoader()); annotationFinder.setWorld(aWorld); this.typeConverter = new JavaLangTypeToResolvedTypeConverter(aWorld); } @@ -253,9 +253,9 @@ public class Java15ReflectionBasedReferenceTypeDelegate extends InternalUseOnlyPointcutParser parser = null; World world = getWorld(); if (world instanceof ReflectionWorld) { - parser = new InternalUseOnlyPointcutParser(classLoader,(ReflectionWorld)getWorld()); + parser = new InternalUseOnlyPointcutParser(classLoaderReference.getClassLoader(), (ReflectionWorld) getWorld()); } else { - parser = new InternalUseOnlyPointcutParser(classLoader); + parser = new InternalUseOnlyPointcutParser(classLoaderReference.getClassLoader()); } Set additionalPointcutHandlers = world.getRegisteredPointcutHandlers(); for (Iterator handlerIterator = additionalPointcutHandlers.iterator(); handlerIterator.hasNext();) { |