Fix AssertThrowsOnLastStatement cursor chain for JavaTemplate compatibility#938
Merged
Fix AssertThrowsOnLastStatement cursor chain for JavaTemplate compatibility#938
Conversation
…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.
2 tasks
Member
Author
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes build failure (10 tests in
AssertThrowsOnLastStatementTest) caused by upstreamopenrewrite/rewrite@76c4321which added a parent-type check inJavaTemplateJavaExtension.visitMethodInvocation. The cursor passed toJavaTemplate.apply()skipped theJ.Blockparent, causing the template engine to incorrectly route toparseExpression()for a statement template, resulting inIndexOutOfBoundsException.The fix inserts the lambda body (
J.Block) into the cursor chain so the upstream check correctly identifies the statement context.Test plan
AssertThrowsOnLastStatementTesttests pass