Skip to content

Conversation

Jenson3210
Copy link
Contributor

What's changed?

Cutting up the task at hand in multiple smaller PR's for better insights, risk assessment...

  • NullCheckAsSwitchCase

What's your motivation?

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@Jenson3210 Jenson3210 self-assigned this Jun 2, 2025
@Jenson3210 Jenson3210 added the recipe Recipe requested label Jun 2, 2025
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Jun 2, 2025
…tchCase.java

Co-authored-by: Jacob van Lingen <jacobvanlingen@hotmail.com>
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Jun 4, 2025
…tchCase.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@Jenson3210
Copy link
Contributor Author

Jenson3210 commented Jun 12, 2025

@timtebeek would you want any further review? Or can I go ahead and do the necessary to merge (adapt the declarative yaml, do the nullcheck only in 1 PR...)

@timtebeek
Copy link
Member

Great work here so far; explored a bit and added more tests and a couple fixes as seen in the diff cfd7189...dcadb16

In the last commit I show we're not consistent with how we handle throws depending on if it's in a block; would we want to make that consistent by allowing J.Throw in the if seen here?

public boolean couldModifyNullCheckedValue() {
Statement statement = whenNull();
if (statement instanceof J.Block || statement instanceof Expression) {
return couldModifyNullCheckedValue(statement, nullCheckedParameter);
}
// Cautious by default
return true;
}

@Jenson3210
Copy link
Contributor Author

Jenson3210 commented Jun 16, 2025

Added the Throws to the if statement.

IntelliJ says only Block, expression or throws is possible so we should be good to go now!

Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@Jenson3210 Jenson3210 merged commit b0b496a into main Jun 16, 2025
2 checks passed
@Jenson3210 Jenson3210 deleted the move_ifnull_to_switch branch June 16, 2025 20:25
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java 21+ recipe Recipe requested
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants