commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1078303 - /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/RulesBinderImpl.java
Date Sat, 05 Mar 2011 15:36:59 GMT
Author: simonetripodi
Date: Sat Mar  5 15:36:59 2011
New Revision: 1078303

URL: http://svn.apache.org/viewvc?rev=1078303&view=rev
Log:
fixed the stacktrace analysis to retrieve the module that raised the error

Modified:
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/RulesBinderImpl.java

Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/RulesBinderImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/RulesBinderImpl.java?rev=1078303&r1=1078302&r2=1078303&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/RulesBinderImpl.java
(original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/internal/rulesbinder/RulesBinderImpl.java
Sat Mar  5 15:36:59 2011
@@ -23,7 +23,6 @@ import java.util.ArrayList;
 import java.util.Formatter;
 import java.util.List;
 
-import org.apache.commons.digester3.AbstractRulesModule;
 import org.apache.commons.digester3.DigesterLoadingException;
 import org.apache.commons.digester3.Rule;
 import org.apache.commons.digester3.RulesBinder;
@@ -65,27 +64,33 @@ public final class RulesBinderImpl imple
      */
     public void addError(String messagePattern, Object... arguments) {
         StackTraceElement[] stackTrace = new Exception().getStackTrace();
-        // let's check if it is an AbstractRulesModule extension first
-        StackTraceElement element = stackTrace[3];
-        Class<?> moduleClass = null;
-
-        try {
-            // check if the set ClassLoader resolves the Class in the StackTrace
-            moduleClass = Class.forName(element.getClassName(), false, this.classLoader);
-        } catch (ClassNotFoundException e) {
+        StackTraceElement element = null;
+
+        int stackIndex = stackTrace.length - 1;
+        while (element == null && stackIndex > 0) {
+            Class<?> moduleClass = null;
             try {
-                // try otherwise with current ClassLoader
-                moduleClass = Class.forName(element.getClassName(), false, this.getClass().getClassLoader());
-            } catch (ClassNotFoundException e1) {
-                // Class in the StackTrace can't be found, don't write the file name:line
number detail in the message
+                // check if the set ClassLoader resolves the Class in the StackTrace
+                moduleClass = Class.forName(stackTrace[stackIndex].getClassName(), false,
this.classLoader);
+            } catch (ClassNotFoundException e) {
+                try {
+                    // try otherwise with current ClassLoader
+                    moduleClass = Class.forName(stackTrace[stackIndex].getClassName(), false,
this.getClass().getClassLoader());
+                } catch (ClassNotFoundException e1) {
+                    // Class in the StackTrace can't be found, don't write the file name:line
number detail in the message
+                }
             }
-        }
 
-        if (moduleClass != null) {
-            // if it is not an AbstractRulesModule, then a RulesModule implementation
-            if (!AbstractRulesModule.class.isAssignableFrom(moduleClass)) {
-                element = stackTrace[2];
+            if (moduleClass != null) {
+                if (RulesModule.class.isAssignableFrom(moduleClass)) {
+                    element = stackTrace[stackIndex];
+                }
             }
+
+            stackIndex--;
+        }
+
+        if (element != null) {
             messagePattern = String.format("%s (%s:%s)", messagePattern, element.getFileName(),
element.getLineNumber());
         }
         this.addError(new ErrorMessage(messagePattern, arguments));



Mime
View raw message