java.lang.StackOverflowError is thrown when a thread's stack, the memory holding its chain of method calls, is exhausted by calls nesting too deeply. In Java this is overwhelmingly a recursion bug: a method that calls itself, directly or through a cycle of methods, without a termination condition that the actual arguments ever satisfy. The stack trace that comes with it looks alarming (it can be thousands of lines), but its repeating pattern is precisely the diagnostic.
toString, an equals/hashCode, or a JSON serializer walking the cycle) without a visited set.IdentityHashMap-based set for traversal and serialization), or exclude the back-reference from serialization, the standard treatment for parent pointers in JSON.ArrayDeque) on the heap handles depths no thread stack will.-Xss2m. Treat needing this as a design smell: if the depth depends on user data, someone will eventually supply deeper data.Why is the stack trace truncated or repetitive? The JVM prints the frames it captured; a recursion cycle produces thousands of near-identical frames and tools truncate them. The repetition is the signal: find the cycle and the two or three distinct frames inside it.
Can a StackOverflowError corrupt data? It can interrupt an operation midway, leaving partially updated structures, which is why it should be treated as a serious bug rather than caught and ignored. Catching it to “keep the app alive” is rarely safe.
How is this different from the JavaScript maximum call stack error? Same underlying mechanism, different platform and wording. The diagnosis transfers directly: find the repeating frames, repair the termination condition.