-
Notifications
You must be signed in to change notification settings - Fork 92
No longer remove String.valueof when it's called on a method invocation #752
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
Merged
Conversation
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
Laurens-W
commented
Oct 8, 2025
| if (VALUE_OF.matches(mi) && mi.getArguments().size() == 1) { | ||
| Expression argument = mi.getArguments().get(0); | ||
| if (TypeUtils.isString(argument.getType()) || removeValueOfForStringConcatenation(argument)) { | ||
| if ((TypeUtils.isString(argument.getType()) && !(argument instanceof J.MethodInvocation)) || removeValueOfForStringConcatenation(argument)) { |
Contributor
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't look into it too much but if we could determine here whether the result of the method invocation is actually nullable that would allow us to make more transformations
timtebeek
approved these changes
Oct 10, 2025
mergify bot
added a commit
to robfrank/linklift
that referenced
this pull request
Oct 15, 2025
… 2.18.0 to 2.19.0 [skip ci] Bumps [org.openrewrite.recipe:rewrite-static-analysis](https://github.com/openrewrite/rewrite-static-analysis) from 2.18.0 to 2.19.0. Release notes *Sourced from [org.openrewrite.recipe:rewrite-static-analysis's releases](https://github.com/openrewrite/rewrite-static-analysis/releases).* > 2.19.0 > ------ > > What's Changed > -------------- > > * Fix FinalClass recipe to correctly handle nested static subclasses by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#742](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/742) > * Add `Objects.requireNonNullElse/ElseGet` support to `AnnotateNullableParameters` by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#743](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/743) > * Fix ReplaceLambdaWithMethodReference handling of nested class imports by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#745](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/745) > * OpenRewrite recipe best practices by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#746](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/746) > * Update recipe documentation examples by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#747](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/747) > * Support for-each loop in NeedBraces by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#749](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/749) > * Update documentation examples by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#750](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/750) > * Update documentation examples by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#751](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/751) > * fixed test that got changed behavior in rewrite-core by [`@Jenson3210`](https://github.com/Jenson3210) in [openrewrite/rewrite-static-analysis#753](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/753) > * No longer remove String.valueof when it's called on a method invocation by [`@Laurens-W`](https://github.com/Laurens-W) in [openrewrite/rewrite-static-analysis#752](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/752) > > New Contributors > ---------------- > > * [`@Jenson3210`](https://github.com/Jenson3210) made their first contribution in [openrewrite/rewrite-static-analysis#753](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/753) > > **Full Changelog**: <openrewrite/rewrite-static-analysis@v2.18.0...v2.19.0> Commits * [`3c1a313`](openrewrite/rewrite-static-analysis@3c1a313) No longer remove String.valueof when it's called on a method invocation ([#752](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/752)) * [`1d8d504`](openrewrite/rewrite-static-analysis@1d8d504) fixed test that got changed behavior in rewrite-core ([#753](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/753)) * [`504a582`](openrewrite/rewrite-static-analysis@504a582) Update documentation examples ([#751](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/751)) * [`cd26b74`](openrewrite/rewrite-static-analysis@cd26b74) Update documentation examples ([#750](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/750)) * [`b80e4b6`](openrewrite/rewrite-static-analysis@b80e4b6) Support for-each loop in NeedBraces ([#749](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/749)) * [`b93d869`](openrewrite/rewrite-static-analysis@b93d869) Update recipe documentation examples ([#747](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/747)) * [`7165caf`](openrewrite/rewrite-static-analysis@7165caf) OpenRewrite recipe best practices ([#746](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/746)) * [`eb91699`](openrewrite/rewrite-static-analysis@eb91699) Fix ReplaceLambdaWithMethodReference handling of nested class imports ([#745](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/745)) * [`a5d78d7`](openrewrite/rewrite-static-analysis@a5d78d7) Polish MoveFieldAnnotationToType * [`0bd9340`](openrewrite/rewrite-static-analysis@0bd9340) Add `Objects.requireNonNullElse/ElseGet` support to `AnnotateNullableParamete... * Additional commits viewable in [compare view](openrewrite/rewrite-static-analysis@v2.18.0...v2.19.0) [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
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.
What's changed?
No longer remove
String.valueofwhen it's called on a method invocationWhat's your motivation?
When the result of the method invocation is nullable it would result in
"null"instead ofnullafter the recipe made changesChecklist