diff options
author | aclement <aclement> | 2008-05-27 18:52:33 +0000 |
---|---|---|
committer | aclement <aclement> | 2008-05-27 18:52:33 +0000 |
commit | 9f5a293b81b32acdffd484f1f65d416f18293953 (patch) | |
tree | 15b4202b75b8523152985f434d903a1c36279add /loadtime | |
parent | 56e0a03e4cb6030fe980c546891214d557070bbd (diff) | |
download | aspectj-9f5a293b81b32acdffd484f1f65d416f18293953.tar.gz aspectj-9f5a293b81b32acdffd484f1f65d416f18293953.zip |
210470: preventing weaver leaks: implement new IWeavingContext method
Diffstat (limited to 'loadtime')
-rw-r--r-- | loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java b/loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java index 6ffd2cb28..6d1a878e4 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java @@ -16,6 +16,7 @@ import java.net.URL; import java.util.Enumeration; import java.util.List; +import org.aspectj.weaver.WeakClassLoaderReference; import org.aspectj.weaver.tools.Trace; import org.aspectj.weaver.tools.TraceFactory; import org.aspectj.weaver.tools.WeavingAdaptor; @@ -27,26 +28,26 @@ import org.aspectj.weaver.tools.WeavingAdaptor; */ public class DefaultWeavingContext implements IWeavingContext { - protected ClassLoader loader; + protected WeakClassLoaderReference loaderRef; private String shortName; private static Trace trace = TraceFactory.getTraceFactory().getTrace(DefaultWeavingContext.class); /** - * Construct a new WeavingContext to use the specifed ClassLoader + * Construct a new WeavingContext to use the specified ClassLoader * This is the constructor which should be used. * @param loader */ public DefaultWeavingContext(ClassLoader loader) { super(); - this.loader = loader; + this.loaderRef = new WeakClassLoaderReference(loader); } /** * Same as ClassLoader.getResources() */ public Enumeration getResources(String name) throws IOException { - return loader.getResources(name); + return getClassLoader().getResources(name); } /** @@ -60,8 +61,14 @@ public class DefaultWeavingContext implements IWeavingContext { * @return classname@hashcode */ public String getClassLoaderName() { + ClassLoader loader = getClassLoader(); return ((loader!=null)?loader.getClass().getName()+"@"+Integer.toHexString(System.identityHashCode(loader)):"null"); } + + + public ClassLoader getClassLoader() { + return loaderRef.getClassLoader(); + } /** * @return filename @@ -88,11 +95,12 @@ public class DefaultWeavingContext implements IWeavingContext { public boolean isLocallyDefined(String classname) { String asResource = classname.replace('.', '/').concat(".class"); - + ClassLoader loader = getClassLoader(); URL localURL = loader.getResource(asResource); if (localURL == null) return false; boolean isLocallyDefined = true; + ClassLoader parent = loader.getParent(); if (parent != null) { URL parentURL = parent.getResource(asResource); @@ -108,7 +116,7 @@ public class DefaultWeavingContext implements IWeavingContext { * @param loader */ public List getDefinitions(final ClassLoader loader, final WeavingAdaptor adaptor) { - if (trace.isTraceEnabled()) trace.enter("getDefinitions",this,new Object[] { loader, adaptor }); + if (trace.isTraceEnabled()) trace.enter("getDefinitions", this, new Object[] { "goo", adaptor }); List definitions = ((ClassLoaderWeavingAdaptor)adaptor).parseDefinitions(loader); |