diff --git a/rewrite-java/src/main/java/org/openrewrite/java/tree/Space.java b/rewrite-java/src/main/java/org/openrewrite/java/tree/Space.java index bc45bce6205..bace53ca9f0 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/tree/Space.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/tree/Space.java @@ -115,6 +115,8 @@ public Space withComments(List comments) { public Space withWhitespace(String whitespace) { if (comments.isEmpty() && whitespace.isEmpty()) { return Space.EMPTY; + } else if (comments.isEmpty() && " ".equals(whitespace)) { + return SINGLE_SPACE; } if ((whitespace.isEmpty() && this.whitespace == null) || whitespace.equals(this.whitespace)) { return this;