Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix StackOverflowError in org.apache.catalina.startup.ContextConfig.populateSCIsForCacheEntry in Tomcat 7.0.35

Tags:

tomcat

We are running an old version of Tomcat, and a new web application has caused a stack trace like this

Caused by: java.lang.StackOverflowError
    at org.apache.catalina.startup.ContextConfig.populateSCIsForCacheEntry(ContextConfig.java:2269)
    at org.apache.catalina.startup.ContextConfig.populateSCIsForCacheEntry(ContextConfig.java:2269)
    at org.apache.catalina.startup.ContextConfig.populateSCIsForCacheEntry(ContextConfig.java:2269)

This has been mentioned at https://bz.apache.org/bugzilla/show_bug.cgi?id=53871, and later versions (like Tomcat 8) don't seem to be affected.

How can I fix this?

like image 947
Phyxx Avatar asked Apr 29 '15 22:04

Phyxx


3 Answers

I had the same problem. For Tomcat 8.* and above, the property name has changed to tomcat.util.scan.StandardJarScanFilter.jarsToSkip.

See: https://tomcat.apache.org/tomcat-8.5-doc/config/systemprops.html#JAR_Scanning

Inside Tomcat directory, edit conf/catalina.properties file, find tomcat.util.scan.StandardJarScanFilter.jarsToSkip property and add the offending jars to the bottom of the list.

e.g

tomcat.util.scan.StandardJarScanFilter.jarsToSkip=\
annotations-api.jar,\
ant-junit*.jar,\
ant-launcher.jar,\
ant.jar,\
...
xmlParserAPIs.jar,\
xom-*.jar,\
bcprov*.jar
like image 96
Marcelo C. Avatar answered Oct 07 '22 12:10

Marcelo C.


Since upgrading Tomcat was not an option, I needed a way to work around this issue.

As it turns out Tomcat 7.0.47 has the same issue, but better reporting. When run locally the reporting showed me this:

Caused by: java.lang.IllegalStateException: Unable to complete the scan for 
annotations for web application [/api] 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 
[org.bouncycastle.asn1.ASN1Boolean->org.bouncycastle.asn1.DERBoolean-
>org.bouncycastle.asn1.ASN1Boolean]

Once I found the offending jar file, I added it to the catalina.properties file like this:

org.apache.catalina.startup.ContextConfig.jarsToSkip=bcprov*.jar

This appears to have worked around the issue in the older version of Tomcat.

like image 23
Phyxx Avatar answered Oct 17 '22 04:10

Phyxx


I run into the same issue with a legacy project I got on recently. I found better solution here: Avoid cyclic reference inheritance in grails

As it turned out I also had two bcprov-jdk on classpath. In my case these were:

bcprov-jdk15on
bcprov-jdk16

Since it is a multimodule Maven project, I used

mvn dependency:tree -Dverbose -Dincludes=org.bouncycastle

to find where they come from. Then I removed the jdk16 since the up to date one is the jdk15on and it works.

like image 21
Ondrej Burkert Avatar answered Oct 17 '22 03:10

Ondrej Burkert