Skip to content

Fix StackOverflowError with JsonValueWriter re-entrancy in ValueProce… - #51589

Open
beligh-hamdi wants to merge 1 commit into
spring-projects:mainfrom
beligh-hamdi:fix-50651-json-value-processor-recursion
Open

Fix StackOverflowError with JsonValueWriter re-entrancy in ValueProce…#51589
beligh-hamdi wants to merge 1 commit into
spring-projects:mainfrom
beligh-hamdi:fix-50651-json-value-processor-recursion

Conversation

@beligh-hamdi

@beligh-hamdi beligh-hamdi commented Sep 4, 2026

Copy link
Copy Markdown

Fix: StackOverflowError at startup with embedded Tomcat, ecs, debug level, and members value processor

This pull request fixes issue #50651 where applications experienced a StackOverflowError at startup when combining embedded Tomcat, ECS structured logging, debug log level, and a custom StructuredLoggingJsonMembersCustomizer applying a members ValueProcessor.

Broken Behavior

During structured JSON serialization of log events (such as exceptions/throwables via Logback's ThrowableProxy), evaluating ValueProcessor instances can inadvertently trigger logging operations or class loading (TomcatEmbeddedWebappClassLoader). If these internal triggers attempt to write JSON or re-evaluate values, it leads to unconstrained re-entrancy and infinite recursion (StackOverflowError).

How the Changes Fix It

  • Added a re-entrancy guard (processingValue flag) to JsonValueWriter#processValue(V) utilizing Java Streams and .reduce() for functional elegance.
  • If value processing is already active for the current writer instance, nested/re-entrant calls safely bypass further processor evaluation.
  • Added a dedicated unit test (valueProcessorShouldNotAllowReentrancy) in JsonValueWriterTests to ensure re-entrant value processing does not cause infinite recursion or throw exceptions.

Fixes #50651

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 4, 2026
…ssor

- Add re-entrancy guard in JsonValueWriter#processValue using Java Streams
- Add unit test verifying ValueProcessor re-entrancy protection

Closes spring-projectsgh-50651

Signed-off-by: Beligh HAMDI <beligh.hamdi@gmail.com>
@beligh-hamdi
beligh-hamdi force-pushed the fix-50651-json-value-processor-recursion branch from 66ff7e3 to 9808dee Compare September 4, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StackOverflowError at startup with embedded Tomcat, ecs, debug level, and members value processor

2 participants