Why java.lang.StackOverflowError occurred?

Solution Verified - Updated

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 error is seen in the logs when the "session data is being replicated"?
  • Why I'm getting StackOverflowError when deploying EAR file?
  • Why liferay WAR application deployment fails with nested exception is java.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 StackOverflowError during 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

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).

Components
Category

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.