Skip to content

Fix AssertThrowsOnLastStatement cursor chain for JavaTemplate compatibility#938

Merged
timtebeek merged 1 commit intomainfrom
tim/fix-build-failures
Mar 24, 2026
Merged

Fix AssertThrowsOnLastStatement cursor chain for JavaTemplate compatibility#938
timtebeek merged 1 commit intomainfrom
tim/fix-build-failures

Conversation

@timtebeek
Copy link
Member

Summary

Fixes build failure (10 tests in AssertThrowsOnLastStatementTest) caused by upstream openrewrite/rewrite@76c4321 which added a parent-type check in JavaTemplateJavaExtension.visitMethodInvocation. The cursor passed to JavaTemplate.apply() skipped the J.Block parent, causing the template engine to incorrectly route to parseExpression() for a statement template, resulting in IndexOutOfBoundsException.

The fix inserts the lambda body (J.Block) into the cursor chain so the upstream check correctly identifies the statement context.

Test plan

  • All 10 previously failing AssertThrowsOnLastStatementTest tests pass
  • Full build passes (1439 tests, 0 failures)

…bility

The cursor passed to JavaTemplate.apply() had the visitor's cursor as
the direct parent of lambdaStatement, skipping the J.Block. Since
openrewrite/rewrite@76c4321 the template engine checks whether the
parent tree is a J.Block to decide between statement and expression
parsing. The incomplete cursor caused it to take the expression path
for a statement template, producing an IndexOutOfBoundsException.

Fix by inserting the lambda body (J.Block) into the cursor chain.
@timtebeek
Copy link
Member Author

@timtebeek timtebeek added bug Something isn't working recipe Recipe request junit labels Mar 24, 2026
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Mar 24, 2026
@timtebeek timtebeek merged commit 72438fc into main Mar 24, 2026
1 check passed
@timtebeek timtebeek deleted the tim/fix-build-failures branch March 24, 2026 19:08
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working junit recipe Recipe request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant