Skip to content

Fix StackOverflowError in Kotlin parser for deeply nested binary expressions#7083

Draft
zieka wants to merge 1 commit intomainfrom
fix/ci-error
Draft

Fix StackOverflowError in Kotlin parser for deeply nested binary expressions#7083
zieka wants to merge 1 commit intomainfrom
fix/ci-error

Conversation

@zieka
Copy link
Copy Markdown
Member

@zieka zieka commented Mar 20, 2026

Summary

  • Converts recursive left-child traversal in KotlinTreeParserVisitor.visitBinaryExpression() to an iterative approach
  • Collects the left spine of nested KtBinaryExpression nodes into a list and processes them bottom-up, preventing StackOverflowError on deeply nested expressions (e.g. 2000+ string concatenations)
  • Updates mapFunctionCall() to accept a pre-computed left expression instead of re-visiting the left child

Fixes the CI failure: https://github.com/openrewrite/rewrite/actions/runs/23356509331/job/67948579231

Test plan

  • BinaryTest.deeplyNestedStringConcatenation() now passes (was failing with StackOverflowError)
  • Full rewrite-kotlin test suite passes (1173 tests, 0 failures)

…essions

Convert recursive left-child traversal in visitBinaryExpression to an
iterative approach, collecting the left spine of nested KtBinaryExpression
nodes and processing them bottom-up. This prevents stack overflow when
parsing deeply nested expressions (e.g. 2000+ string concatenations).
@greg-at-moderne
Copy link
Copy Markdown
Contributor

Should

be re-enabled?

Copy link
Copy Markdown
Member

@sambsnyd sambsnyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me. Why is this still a draft?

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Ready to Review

Development

Successfully merging this pull request may close these issues.

4 participants