[jboss-cvs] JBossAS SVN: r69697 - in projects/aop/trunk/aop: src/main/org/jboss/aop and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Feb 7 10:52:29 EST 2008
Author: kabir.khan at jboss.com
Date: 2008-02-07 10:52:29 -0500 (Thu, 07 Feb 2008)
New Revision: 69697
Modified:
projects/aop/trunk/aop/.classpath
projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
Log:
[JBAOP-524] Don't try to load up annotations, if we already failed loading with that classloader
Modified: projects/aop/trunk/aop/.classpath
===================================================================
--- projects/aop/trunk/aop/.classpath 2008-02-07 12:51:16 UTC (rev 69696)
+++ projects/aop/trunk/aop/.classpath 2008-02-07 15:52:29 UTC (rev 69697)
@@ -12,7 +12,7 @@
<classpathentry kind="lib" path="/thirdparty/jboss/profiler/jvmti/lib/jboss-profiler-jvmti.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss/common-logging-spi/lib/jboss-logging-spi.jar" sourcepath="/thirdparty/jboss/common-logging-spi/lib/jboss-logging-spi-sources.jar"/>
<classpathentry kind="lib" path="/thirdparty/javassist/lib/javassist.jar"/>
- <classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-container.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-container-src.zip"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-container.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-container-sources.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss/test/lib/jboss-test.jar" sourcepath="/thirdparty/jboss/test/lib/jboss-test-src.zip"/>
<classpathentry kind="lib" path="/thirdparty/jboss/common-core/lib/jboss-common-core.jar" sourcepath="/thirdparty/jboss/common-core/lib/jboss-common-core-sources.jar"/>
<classpathentry kind="lib" path="/thirdparty/apache-log4j/lib/log4j.jar"/>
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java 2008-02-07 12:51:16 UTC (rev 69696)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java 2008-02-07 15:52:29 UTC (rev 69697)
@@ -37,6 +37,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -384,8 +385,14 @@
throw new RuntimeException("annotation or annotationClass must be passed in");
}
- annotationClass = loadAnnotationClass(tgt, annotation, annotationClass);
- if (annotationClass != null && metadata != null && metadata.isAnnotationPresent(annotationClass)) return true;
+ if (metadata != null)
+ {
+ if (annotationClass == null)
+ {
+ annotationClass = loadAnnotationClass(tgt, annotation);
+ }
+ if (annotationClass != null && metadata.isAnnotationPresent(annotationClass)) return true;
+ }
if (annotation == null)
{
@@ -508,20 +515,23 @@
throw new RuntimeException("annotation or annotationClass must be passed in");
}
- annotationClass = loadAnnotationClass(m.getDeclaringClass(), annotation, annotationClass);
-
- if (annotation == null)
- {
- annotation = annotationClass.getName();
- }
if (metadata != null)
{
- if (hasJoinPointAnnotation(m.getDeclaringClass(), new MethodSignature(m), annotationClass))
+ if (annotationClass == null)
{
+ annotationClass = loadAnnotationClass(m.getDeclaringClass(), annotation);
+ }
+
+ if (annotationClass != null && hasJoinPointAnnotation(m.getDeclaringClass(), new MethodSignature(m), annotationClass))
+ {
return true;
}
}
+ if (annotation == null)
+ {
+ annotation = annotationClass.getName();
+ }
if (annotations.hasAnnotation(m, annotation)) return true;
try
{
@@ -587,7 +597,7 @@
private boolean hasJoinPointAnnotationFromStringName(Class declaringClass, org.jboss.metadata.spi.signature.Signature sig, String annotationName)
{
- Class annotationClass = loadAnnotationClass(declaringClass, annotationName, null);
+ Class annotationClass = loadAnnotationClass(declaringClass, annotationName);
if (annotationClass != null)
{
return this.hasJoinPointAnnotation(declaringClass, sig, annotationClass);
@@ -647,30 +657,24 @@
return AnnotationElement.isAnyAnnotationPresent(member, annotation);
}
- private Class loadAnnotationClass(Class tgt, String annotation, Class annotationClass)
+ private Class loadAnnotationClass(Class tgt, String annotation)
{
- if (annotationClass != null)
- {
- return annotationClass;
- }
- if (annotation == null)
- {
- throw new RuntimeException("Both annotation and annotationClass were null");
- }
+ ClassLoader cl = null;
try
{
- if (metadata != null)
+ cl = SecurityActions.getClassLoader(tgt);
+ if (cl == null)
{
- if (annotationClass == null)
- {
- ClassLoader cl = SecurityActions.getClassLoader(tgt);
- if (cl == null)
- {
- cl = SecurityActions.getContextClassLoader();
- }
- return cl.loadClass(annotation);
- }
+ cl = SecurityActions.getContextClassLoader();
}
+
+ if (isIgnored(cl, annotation))
+ {
+ return null;
+ }
+
+ Class clazz = cl.loadClass(annotation);
+ return clazz;
}
catch (ClassNotFoundException e)
{
@@ -680,9 +684,50 @@
{
//The classloader may be invalid, just ignore this
}
+ recordIgnored(cl, annotation);
return null;
}
+ static WeakHashMap<ClassLoader, HashSet<String>> ignoredAnnotations = new WeakHashMap<ClassLoader, HashSet<String>>();
+ static ReentrantReadWriteLock ignoredAnnotationsLock = new ReentrantReadWriteLock();
+ private void recordIgnored(ClassLoader loader, String annotationName)
+ {
+ ignoredAnnotationsLock.writeLock().lock();
+ try
+ {
+ HashSet<String> annotationNames = ignoredAnnotations.get(loader);
+ if (annotationNames == null)
+ {
+ annotationNames = new HashSet<String>();
+ ignoredAnnotations.put(loader, annotationNames);
+ }
+ annotationNames.add(annotationName);
+ }
+ finally
+ {
+ ignoredAnnotationsLock.writeLock().unlock();
+ }
+ }
+
+ private boolean isIgnored(ClassLoader loader, String annotationName)
+ {
+ ignoredAnnotationsLock.readLock().lock();
+ try
+ {
+ HashSet<String> annotationNames = ignoredAnnotations.get(loader);
+ if (annotationNames != null)
+ {
+ return annotationNames.contains(annotationName);
+ }
+ }
+ finally
+ {
+ ignoredAnnotationsLock.readLock().unlock();
+ }
+ return false;
+ }
+
+
/**
* Get the metadata
*
More information about the jboss-cvs-commits
mailing list