Author: markt
Date: Tue Feb 19 16:24:02 2013
New Revision: 1447792

URL: http://svn.apache.org/r1447792
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53871
Add the class hierarchy that triggered the StackOverflowError to the error 
message to aid debugging.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java
    
tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1447791

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1447792&r1=1447791&r2=1447792&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java 
Tue Feb 19 16:24:02 2013
@@ -2103,13 +2103,7 @@ public class ContextConfig implements Li
 
         ClassParser parser = new ClassParser(is, null);
         JavaClass clazz = parser.parse();
-        try {
-            checkHandlesTypes(clazz);
-        } catch (StackOverflowError soe) {
-            throw new IllegalStateException(sm.getString(
-                    "contextConfig.annotationsStackOverflow",
-                    context.getName()), soe);
-        }
+        checkHandlesTypes(clazz);
 
         if (handlesTypesOnly) {
             return;
@@ -2159,7 +2153,14 @@ public class ContextConfig implements Li
             populateJavaClassCache(className, javaClass);
             JavaClassCacheEntry entry = javaClassCache.get(className);
             if (entry.getSciSet() == null) {
-                populateSCIsForCacheEntry(entry);
+                try {
+                    populateSCIsForCacheEntry(entry);
+                } catch (StackOverflowError soe) {
+                    throw new IllegalStateException(sm.getString(
+                            "contextConfig.annotationsStackOverflow",
+                            context.getName(),
+                            classHierarchyToString(className, entry)));
+                }
             }
             if (entry.getSciSet().size() > 0) {
                 // Need to try and load the class
@@ -2211,6 +2212,30 @@ public class ContextConfig implements Li
     }
 
 
+    private String classHierarchyToString(String className,
+            JavaClassCacheEntry entry) {
+        JavaClassCacheEntry start = entry;
+        StringBuilder msg = new StringBuilder(className);
+        msg.append("->");
+
+        String parentName = entry.getSuperclassName();
+        JavaClassCacheEntry parent = javaClassCache.get(parentName);
+        int count = 0;
+
+        while (count < 100 && parent != null && parent != start) {
+            msg.append(parentName);
+            msg.append("->");
+
+            count ++;
+            parentName = parent.getSuperclassName();
+            parent = javaClassCache.get(parentName);
+        }
+
+        msg.append(parentName);
+
+        return msg.toString();
+    }
+
     private void populateJavaClassCache(String className, JavaClass javaClass) 
{
         if (javaClassCache.containsKey(className)) {
             return;

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties?rev=1447792&r1=1447791&r2=1447792&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties 
(original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties 
Tue Feb 19 16:24:02 2013
@@ -18,7 +18,7 @@ catalina.noCluster=Cluster RuleSet not f
 catalina.shutdownHookFail=The shutdown hook experienced an error while trying 
to stop the server
 catalina.stopServer=No shutdown port configured. Shut down server through OS 
signal. Server not shut down.
 contextConfig.altDDNotFound=alt-dd file {0} not found
-contextConfig.annotationsStackOverflow=Unable to complete the scan for 
annotations for web application [{0}]. Possible root causes include a too low 
setting for -Xss and illegal cyclic inheritance dependencies
+contextConfig.annotationsStackOverflow=Unable to complete the scan for 
annotations for web application [{0}] due to a StackOverflowError. Possible 
root causes include a too low setting for -Xss and illegal cyclic inheritance 
dependencies. The class hierarchy being processed was [{1}]
 contextConfig.applicationUrl=Unable to determine URL for application web.xml
 contextConfig.applicationMissing=Missing application web.xml, using defaults 
only
 contextConfig.applicationParse=Parse error in application web.xml file at {0}

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1447792&r1=1447791&r2=1447792&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Tue Feb 19 16:24:02 2013
@@ -66,6 +66,12 @@
         Add one more library from JDK 7 to the value of <code>jarsToSkip</code>
         property in the <code>catalina.properties</code> file. (kkolinko)
       </update>
+      <add>
+        <bug>53871</bug>: If annotation scanning results in a
+        <code>StackOverflowError</code> due to broken class dependencies, add
+        the class hierarchy that triggered the exception to the error message.
+        (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Web applications">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to