# java.lang.StackOverflowError

**Code:** `StackOverflowError` · **Category:** Java · **Seen on:** Java, Android

The thread’s call stack overflowed — almost always unbounded recursion, sometimes a bidirectional toString/equals/JSON cycle.

## Meaning

The stack trace repeats the same few frames. Common non-obvious sources: JPA entities with bidirectional relations in `toString()`/`hashCode()` (Lombok @Data), Jackson serialising cycles, and Spring beans calling each other.

## Common causes

- Recursion without a terminating condition
- Lombok @Data / toString on bidirectional JPA relations
- Jackson serialising parent ↔ child references
- Very deep (legitimate) recursion on large inputs

## Quick fix

1. Find the repeating frames in the trace
2. Exclude back-references from toString/equals (`@ToString.Exclude`)
3. Use `@JsonManagedReference`/`@JsonBackReference` or DTOs
4. Convert deep recursion to iteration, or raise `-Xss` as a last resort

## Detailed fix by platform

### Java

1. Break JPA/Lombok cycles:

```java
@Entity @Getter @Setter
public class Order {
    @ManyToOne
    @ToString.Exclude @EqualsAndHashCode.Exclude
    @JsonBackReference
    private Customer customer;
}
```


## How to diagnose

1. **Frames** — Which methods repeat?
2. **Entities** — toString/equals/JSON cycles?
3. **Input size** — Legitimately deep recursion?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/java/stackoverflowerror)
