Why java.lang.StackOverflowError occurred?
Environment
- Java
- Red Hat JBoss Enterprise Application Platform (EAP)
- Apache Tomcat
Issue
- Why Java application server (JBoss EAP or Tomcat) shuts down automatically with
StackOverflowError? - Why
stackoverflow erroris seen in the logs when the "session data is being replicated"? - Why I'm getting
StackOverflowErrorwhen deploying EAR file? - Why
liferayWAR application deployment fails with nested exception isjava.lang.StackOverflowError? - Why following error is coming in the JBoss
"server log"?
ERROR [org.jboss.mx.loading.LoadMgr3] Not rescheduling failed loading task,
loadTask=org.jboss.mx.loading.ClassLoadingTask@1923ca5{classname: org.omg.ETF._ConnectionLocalBase, requestingThread: Thread[main,5,jboss],
requestingClassLoader: org.jboss.mx.loading.UnifiedClassLoader3@171f189{ url=null ,addedOrder=2}, loadedClass: nullnull, loadOrder: 2147483647,
loadException: java.lang.StackOverflowError, threadTaskCount: 0, state: 1, #CCE: 1}
java.lang.StackOverflowError
at java.lang.Exception.<init>(Exception.java:59)
at java.lang.ClassNotFoundException.<init>(ClassNotFoundException.java:65)
...
-
We are having problems with
java.lang.StackOverflowError. what exactly needs to be done. Also let us know what all information is required to attach in the support case to confirm this. -
We are experiencing a
StackOverflowErrorduring some kind of serialization the JBoss EAP is performing. The stacktrace is filled up with:
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1189)
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
- The exception stacktrace gives no info apart from this method calls logs. Is there any way we can find what the JBoss EAP is trying to serialize? Maybe using some option that enables the full stack trace?
Resolution
Increase the thread stack size by increments of 64k until the StackOverflowError disappears. See How do I set Java thread stack size? and What is the default Java thread stack size? for references. For recursion issues in serialization, refer to StackOverflowError in JBoss Serialization
Alternative, modify the code or configuration(s) to avoid recursion or infinite loops.
Root Cause
- The amount of stack space required by the program exceeds (than JVM allocated size) for the following reasons:
- The program and/or use-case requires a larger stack (e.g., graphics-intensive programs).
- The application is deeply-nested (recursion).
- Infinite loops
- Java thread stack overflow caused by Oracle JDBC driver
- Java thread stack overflow caused by JSP include endless loop
- java.lang.StackOverflowError when a JSP request hits an exception
- JBoss throws a StackOverflowError due to deep recursion in BaseClassLoader
- JBoss EAP fatal StackOverflowError occurs during session passivation
- StackOverflow raised in EAP 6 by TRACE classloading logging
- StackOverflow in org.jboss.wildfly.naming.client during deployment
- EAP web request failing with StackOverflowError in JBoss EAP 7
- EAP 7 Undertow AjpReadListener throws StackOverflowError
- java.lang.StackOverflowError in org.jboss.jca during XAManagedConnection.end error handling in JBoss EAP
Diagnostic Steps
Check if the thread stack size being explicitly set. The JVM by default can limit the depth of an exception stack trace. With really deep recursion, that may mean more interesting code calls where the StackOverflow originates is not seen.
If need to see more of the exception trace for further debugging, set a larger -XX:MaxJavaStackTraceDepth=1073741823 in JVM options (defaults to just 1024 lines).
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.