diff --git a/src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNullVisitor.java b/src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNullVisitor.java index 932d2d6dd..55dc96974 100644 --- a/src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNullVisitor.java +++ b/src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNullVisitor.java @@ -157,7 +157,7 @@ public RemoveUnnecessaryNullCheck(J.Binary scope) { public J visitBinary(J.Binary binary, P p) { if (scope.isScope(binary)) { done = true; - return binary.getRight().withPrefix(Space.EMPTY); + return binary.getRight(); } return super.visitBinary(binary, p); } diff --git a/src/test/java/org/openrewrite/staticanalysis/EqualsAvoidsNullTest.java b/src/test/java/org/openrewrite/staticanalysis/EqualsAvoidsNullTest.java index 629289ae0..495ac2978 100644 --- a/src/test/java/org/openrewrite/staticanalysis/EqualsAvoidsNullTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/EqualsAvoidsNullTest.java @@ -407,5 +407,33 @@ private boolean isBar(String bar) { ) ); } + + @Test + @Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/434") + void missingWhitespace() { + rewriteRun( + // language=java + java( + """ + class A { + private static final String FOO = "FOO"; + + boolean withParentExpression(String foo) { + return foo != null && foo.equals(FOO); + } + } + """, + """ + class A { + private static final String FOO = "FOO"; + + boolean withParentExpression(String foo) { + return FOO.equals(foo); + } + } + """ + ) + ); + } } }