Fix ThisAccess to actually match this expressions#95
Merged
Conversation
`ThisAccess.Factory.viewOf` checked for `"super"` instead of `"this"`, so `Expr.viewOf(cursor)` never resolved for `this` identifiers. This caused `DataFlowNode.of` to return `none` and `ForwardFlow.computeVariableAssignment` to throw `Unable to create DataFlowNode` whenever `this` appeared as an argument to a method invocation along a tracked flow path.
this expressionsThisAccess to actually match this expressions
3 tasks
knutwannheden
added a commit
to openrewrite/rewrite-static-analysis
that referenced
this pull request
Apr 21, 2026
…ent (#864) Covers the dataflow crash fixed in openrewrite/rewrite-analysis#95, where the recipe threw `Unable to create DataFlowNode` when a `Stack` variable shared a method with a call that passed `this` as an argument.
Contributor
|
Oops 😆 🙈 Good fix |
3 tasks
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.
Motivation
The
ThisAccess.Factory.viewOffactory — meant to create a trait view forthisidentifiers — checked for the string"super"instead of"this". As a result,Expr.viewOf(cursor)never resolved for athisidentifier; everythisexpression fell through the trait factory chain:ThisAccessrejectedthis(because it was looking forsuper)SuperAccessalso rejectedthisVarAccessdoesn't handlethisExprFallbackexplicitly rejectsJ.IdentifierSo
DataFlowNode.of(cursor)returnednonefor anythisidentifier.ForwardFlow.computeVariableAssignmentthen threwUnable to create DataFlowNodeviaofOrThrowwhenever the algorithm iterated method-invocation arguments and encounteredthis. This broke any downstream recipe relying on local dataflow (for exampleReplaceStackWithDeque) on code that passedthisinto a method call along a tracked flow path.Originally surfaced as a crash in
ReplaceStackWithDequeon real-world code infinos/messageml-utilsandfinos/tracdapwhereresult.add(this)andvalidator.apply(target, arg, this)appeared in the same method as aStackvariable.Summary
ThisAccess.Factory.viewOffrom"super"to"this"DataFlowNodeTest.thisIsADataFlowNode— verifiesDataFlowNode.ofnow resolves for athisidentifierFindLocalFlowPathsStringTest.flowWhereThisIsAnotherArgument— regression test that crashes before this fix (identicalUnable to create DataFlowNodestack trace) and passes afterTest plan
./gradlew testpasses with the fixFindLocalFlowPathsStringTest.flowWhereThisIsAnotherArgumentto fail with the original production stack trace (DataFlowNode.ofOrThrow→ForwardFlow.computeVariableAssignment:467)ReplaceStackWithDequereproducer (rewrite-static-analysis) that previously crashed onresult.add(this)— recipe now runs cleanly after publishing this change to Maven Local