Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preconditions.checkNotNull recipes should retain unrelated String.valueOf(String) #575

Merged
merged 4 commits into from
Oct 11, 2024

Conversation

amishra-u
Copy link
Contributor

@amishra-u amishra-u commented Oct 10, 2024

What's changed?

String.valueOf(String) and the String itself are not equivalent, especially when the value of the String is null. When the String is null, String.valueOf(String) returns the literal "null", whereas directly referencing the String would result in a null value.
Also the intended purpose of recipe (String.ofValue) was to only update the expressions which was previously updated by "PreconditionsCheckNotNullWithMessageToObjectsRequireNonNull", in such case adding a marker to the expression and then selectively updating the marked expression is desired but it seems difficult to do with refasterstyle templates.

So deleted the refaster template for this conversion.

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

Copy link
Contributor

@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.

Great to see this improve the specificity of the recipes. Thanks a lot @amishra-u

@timtebeek timtebeek changed the title Delete String.valueOf(string) to string conversion Preconditions.checkNotNull recipes should retain unrelated String.valueOf(String) Oct 11, 2024
@timtebeek timtebeek added the enhancement New feature or request label Oct 11, 2024
@timtebeek timtebeek merged commit 88fbdcc into openrewrite:main Oct 11, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants