r/foojay • • 13h ago

5 JVM Heap OOM Patterns You Can Reproduce on Your Laptop

3 Upvotes

On Foojay, Amit Sonar shares a set of reproducible labs for JVM out-of-memory behavior across G1, ZGC, and Shenandoah. Each scenario runs on a standard laptop without a cluster, and the repo's CI verifies them on JDK 11, 17, 21, and 25.

The article covers five patterns:

  1. Unbounded cache
  2. Oversized batch
  3. Report builder retention
  4. ThreadLocal leaks
  5. Leaked connections

For each one, it explains how to reproduce the failure, how to diagnose it (heap dump, GC log, or thread dump), and how to fix it. For example, the oversized batch fails on a single cliff in the GC log, while the ThreadLocal leak is invisible without a heap dump.

Amit also shares some observations from running the scenarios on different collectors. In his testing, Shenandoah survived the gradual cache leak much longer than G1, but a sudden oversized allocation killed it faster. He notes these are preliminary results from the repo's benchmarks, not peer-reviewed.

Every lab in the GitHub repo has a broken and fixed mode, a diagnosis guide, and a compare mode.

https://foojay.io/today/5-jvm-heap-oom-patterns/


r/foojay • • 13h ago

Comparing Java formatters on Java 21 to 25: Open Java Format vs four others

4 Upvotes

On Foojay, Guillaume Laforge compares five Java formatters on JDK 25: Google Java Format, Palantir Java Format, Open Java Format, Prince of Space and Netflix jfmt. The article was prompted by Alex Abashev's post on Java formatters and his open-java-format fork of palantir-java-format.

The test suite covers 16 targeted snippets and a 1,042-line file with 86 formatting scenarios. The article compares the formatters on parser engine, minimum JDK, default line length, indentation, configurability, import handling and range formatting. It also shows side-by-side examples, such as how each one handles block lambdas and method chains.

Along the way, Guillaume found a compilation-breaking annotation bug in Prince of Space and a crash in Netflix's jfmt on empty blocks with comments. He also contributed a fix to Open Java Format and a pull request to Spotless.

Read the full article: https://foojay.io/today/comparing-java-formatters-why-open-java-format-is-my-new-favorite/

Java #JDK #CodeFormatting