https://issues.apache.org/jira/browse/EXTSCRIPT-133

git-svn-id: https://svn.apache.org/repos/asf/myfaces/extensions/scripting/trunk@948042 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/api/BaseWeaver.java b/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/api/BaseWeaver.java
index 7e577ed..e793f92 100644
--- a/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/api/BaseWeaver.java
+++ b/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/api/BaseWeaver.java
@@ -30,6 +30,7 @@
 import javax.faces.context.FacesContext;
 import java.io.File;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -450,12 +451,20 @@
          * at the next refresh the second step of the registration cycle should pick the new class up
          *
          */
-        if (_annotationScanner != null && FacesContext.getCurrentInstance() != null && retVal != null) {
-            _annotationScanner.scanClass(retVal);
+        try {
+            if (!scanAnnotation.containsKey(retVal.getName()) && _annotationScanner != null && FacesContext.getCurrentInstance() != null && retVal != null) {
+                scanAnnotation.put(retVal.getName(), "");
+                _annotationScanner.scanClass(retVal);
+            }
+        } finally {
+            scanAnnotation.remove(retVal.getName());
         }
 
         return retVal;
     }
+    //blocker to prevent recursive calls to the annotation scan which can be triggered by subsequent calls of scanAnnotation and loadClass
+    //a simple boolean check does not suffice here because scanClass might trigger subsequent calls to other classes
+    Map<String, String> scanAnnotation = new ConcurrentHashMap<String, String>();
 
     private void recompileRefresh() {
         synchronized (RefreshContext.COMPILE_SYNC_MONITOR) {