TomCat Servlet 执行java.lang.StackOverflowError 异常

TomCat Servlet execution java.lang.StackOverflowError exception

我在服务重启后第一次调用 Apache TomCat 8.5.51 时随机收到以下错误。错误会在一段时间后自动消失,这使得调试变得非常困难。

可能是什么原因?

错误日志:

    27-Jul-2021 13:40:44.965 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log ContextListener: attributeAdded('StockTicker', 'async.Stockticker@75f16954')
    27-Jul-2021 13:41:03.686 SEVERE [http-nio-8080-exec-1] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [Cocoon] in context with path [/cocoon-2.1.11] threw exception [Servlet execution threw an exception] with root cause
        java.lang.WhosebugError
            at org.apache.xml.utils.SuballocatedIntVector.<init>(SuballocatedIntVector.java:115)
            at org.apache.xml.dtm.ref.DTMDefaultBase.<init>(DTMDefaultBase.java:207)
            at org.apache.xml.dtm.ref.DTMDefaultBaseTraversers.<init>(DTMDefaultBaseTraversers.java:90)
            at org.apache.xml.dtm.ref.DTMDefaultBaseIterators.<init>(DTMDefaultBaseIterators.java:85)
            at org.apache.xml.dtm.ref.sax2dtm.SAX2DTM.<init>(SAX2DTM.java:253)
            at org.apache.xml.dtm.ref.sax2dtm.SAX2DTM.<init>(SAX2DTM.java:224)
            at org.apache.xml.dtm.ref.sax2dtm.SAX2RTFDTM.<init>(SAX2RTFDTM.java:126)
            at org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DTMManagerDefault.java:307)
            at org.apache.xpath.XPathContext.getRTFDTM(XPathContext.java:1258)
            at org.apache.xpath.XPathContext.pushRTFContext(XPathContext.java:1275)
            at org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:386)
            at org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
            at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
            at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
            at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)

java.lang.WhosebugError 根据 docs

Thrown when a stack overflow occurs because an application recurses too deeply.

从堆栈跟踪中,可以在下面的行中看到递归。 ElemTemplate.execute 调用 TransformerImpl.executeChildTemplates 进而调用前者从而建立递归:

org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394). 

xml 结构中的某些内容或解析它的代码可能导致 java.lang.WhosebugError
也可能值得检查 -Xss jvm setting.