Skip to content

Conversation

@timtebeek
Copy link
Member

Summary

Changes

  • Added assignmentsMightSideEffect() to check if assignments could have side effects
  • Added expressionMightThrowException() to specifically detect method calls that might throw
  • Added isAssignmentInTryBlock() to identify assignments within try block scope
  • Added test case demonstrating the fix

Test plan

  • Added test doNotRemoveVariableAssignmentWithPotentialSideEffects for the reported issue
  • All existing RemoveUnusedLocalVariablesTest tests pass
  • Verified handleVariablesReadWithinTry test still works correctly

🤖 Generated with Claude Code

…cts in try blocks

The recipe was incorrectly removing variable assignments in try blocks even when
those assignments could throw exceptions and change program behavior. This fix
ensures that method invocations within try blocks are preserved since they may
throw exceptions that affect control flow.

Fixes #740

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Sep 26, 2025
@timtebeek timtebeek self-assigned this Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants