Skip to content

C1: NoValueOfOnStringType keeps one String.valueOf when both concatenation operands are valueOf calls - #1127

Merged
timtebeek merged 1 commit into
mainfrom
c1-no-valueof-both-operands
Oct 25, 2026
Merged

timtebeek merged 1 commit into
mainfrom
c1-no-valueof-both-operands

Conversation

@timtebeek

Copy link
Copy Markdown
Member

Fixes C1 of #1116: NoValueOfOnStringType (in CommonStaticAnalysis) turned String.valueOf(a) + String.valueOf(b) with int operands into a + b, so string concatenation silently became integer addition.

Each operand was checked against the original binary, where the other operand was still a String-typed valueOf call, so both calls were removed. The left operand now keeps its call when the right operand is a String.valueOf(primitive) that will lose its own, which gives String.valueOf(a) + b. When the right argument is a String, both calls are still removed, because the result stays a concatenation.

Verified with ./gradlew test --tests "*NoValueOfOnStringType*" --tests "*CommonStaticAnalysis*": the new keepOneValueOfWhenBothOperandsAreValueOf test fails on main (it produced a + b and a + b + a) and passes here.

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Oct 25, 2026
@timtebeek
timtebeek merged commit 4355003 into main Oct 25, 2026
3 checks passed
@timtebeek
timtebeek deleted the c1-no-valueof-both-operands branch October 25, 2026 17:41
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant