Skip to content

Prevent StackOverflowError in ResolverFully#2297

Merged
ewaostrowska merged 2 commits intoswagger-api:masterfrom
thc202:bug/1751-fix-stackoverflow
Apr 15, 2026
Merged

Prevent StackOverflowError in ResolverFully#2297
ewaostrowska merged 2 commits intoswagger-api:masterfrom
thc202:bug/1751-fix-stackoverflow

Conversation

@thc202
Copy link
Copy Markdown
Contributor

@thc202 thc202 commented Mar 24, 2026

Description

Add guard to resolve schemas just once to prevent loops/stack overflows.

ResolverFully.resolveSchema() threw java.lang.StackOverflowError when parsing
OpenAPI documents that contain recursive schema definitions. For example: a schema
whose additionalProperties.oneOf references itself, or a tree-shaped model whose
items points back to the parent type.

Two-phase guard:

Phase Mechanism Keyed by Catches
In-progress schemasInProgress object identity cycles found during descent
Completed resolvedSchemas object identity repeated resolution of already-resolved schemas

Fix #1751.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor (non-breaking change)
  • 🧪 Tests
  • 📝 Documentation
  • 🧹 Chore (build or tooling)

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • I have linked related issues (if any)

Add guard to resolve just once to prevent loops/stack overflows.

Issue swagger-api#1751.

Signed-off-by: thc202 <thc202@gmail.com>
@ewaostrowska ewaostrowska force-pushed the bug/1751-fix-stackoverflow branch from 3ab57a3 to 936f8c2 Compare April 15, 2026 07:59
@ewaostrowska
Copy link
Copy Markdown
Contributor

Hi @thc202,
Thank you for providing this PR and working on this long standing issue :)

The solution you came up with has covered most of the cases here, but not all. resolvedSchema only did memorize the already processed schemas, but did not cover the schemas currently being resolved. So the solution would not work for case where: resolving schema A reaches A again through properties, etc before the first call completes or resolving A, the resolver may enter B, which re-enters A before A is in the completed cache (A -> B -> A)

I have introduced in-progress cache as well for that reason.

@ewaostrowska ewaostrowska merged commit 9e2ff91 into swagger-api:master Apr 15, 2026
7 checks passed
@thc202 thc202 deleted the bug/1751-fix-stackoverflow branch April 15, 2026 11:17
@thc202
Copy link
Copy Markdown
Contributor Author

thc202 commented Apr 15, 2026

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java.lang.StackOverflowError during parsing recursive schemas/components in ResolverFully.resolveSchema()

3 participants