You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Verified the issue on rewrite-analysis head and latest-release 2.13.1
How are you running OpenRewrite?
Confirmed the bug by writing unit-test in rewrite-analysis.
What is the smallest, simplest way to reproduce the problem?
Flow path analysis currently fails for chained lambda expressions. The issue arises because the lambda end is marked as ControlFlowNode.End, causing subsequent lambdas in the chain to be skipped.
@TestvoidflowPathDetectionWithChainedLambdas() {
//language=javarewriteRun(
spec -> spec.expectedCyclesThatMakeChanges(1).cycles(1),
java(
""" import java.util.List; import java.util.stream.Stream; class Test { void test() { List<Integer> list = Stream.of(1, 2, 3).peek(i -> { System.out.println("Number " + i); }).peek(i -> { int n = 42; int o = n; System.out.println(o); int p = o; }).toList(); } } """, """ import java.util.List; import java.util.stream.Stream; class Test { void test() { List<Integer> list = Stream.of(1, 2, 3).peek(i -> { System.out.println("Number " + i); }).peek(i -> { int n = /*~~>*/42; int o = /*~~>*/n; System.out.println(/*~~>*/o); int p = /*~~>*/o; }).toList(); } } """
)
);
}
What did you expect to see?
The test should pass, with flow paths properly detected and marked in the chained lambda expressions.
What did you see instead?
The recipe fails to make any changes, as the flow path detection skips subsequent lambdas in the chain.
Solution:
The current implementation marks the parent method body as the start node when identifying flow paths for expressions inside a lambda body. Instead, the lambda body itself should be marked as the start node. This approach aligns with JLS §15.27.2, by which we can infer that expressions within a lambda body cannot assign values to variables declared outside of that lambda body.
Are you interested in [contributing a fix to OpenRewrite]
Yes.
The text was updated successfully, but these errors were encountered:
What version of OpenRewrite are you using?
Verified the issue on rewrite-analysis head and latest-release 2.13.1
How are you running OpenRewrite?
Confirmed the bug by writing unit-test in rewrite-analysis.
What is the smallest, simplest way to reproduce the problem?
Flow path analysis currently fails for chained lambda expressions. The issue arises because the lambda end is marked as ControlFlowNode.End, causing subsequent lambdas in the chain to be skipped.
Added below unit-test to the FindLocalFlowPathsNumericTest class to confirm the issue:
What did you expect to see?
The test should pass, with flow paths properly detected and marked in the chained lambda expressions.
What did you see instead?
The recipe fails to make any changes, as the flow path detection skips subsequent lambdas in the chain.
Solution:
The current implementation marks the parent method body as the start node when identifying flow paths for expressions inside a lambda body. Instead, the lambda body itself should be marked as the start node. This approach aligns with JLS §15.27.2, by which we can infer that expressions within a lambda body cannot assign values to variables declared outside of that lambda body.
Are you interested in [contributing a fix to OpenRewrite]
Yes.
The text was updated successfully, but these errors were encountered: