Skip to content

Commit

Permalink
Don't print markers into modified source files
Browse files Browse the repository at this point in the history
The commit eece2d4 intended to do this already, but ended up using the wrong overload of the `SourceFile#printAll()` method.

Fixes #522
Related: #478, openrewrite/rewrite#2982
  • Loading branch information
knutwannheden committed Mar 20, 2023
1 parent 521bf76 commit 8d3a799
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.apache.maven.plugin.MojoExecutionException;
import org.openrewrite.FileAttributes;
import org.openrewrite.PrintOutputCapture;
import org.openrewrite.Result;
import org.openrewrite.binary.Binary;
import org.openrewrite.ipc.http.HttpUrlConnectionSender;
Expand Down Expand Up @@ -189,7 +190,7 @@ private static void writeAfter(Path root, Result result) {
} else {
Charset charset = result.getAfter().getCharset() == null ? StandardCharsets.UTF_8 : result.getAfter().getCharset();
try (BufferedWriter sourceFileWriter = Files.newBufferedWriter(targetPath, charset)) {
sourceFileWriter.write(new String(result.getAfter().printAll(new SanitizedMarkerPrinter()).getBytes(charset), charset));
sourceFileWriter.write(result.getAfter().printAll(new PrintOutputCapture<>(0, new SanitizedMarkerPrinter())));
} catch (IOException e) {
throw new UncheckedIOException("Unable to rewrite source files", e);
}
Expand Down

0 comments on commit 8d3a799

Please sign in to comment.