From ad4fb011d3a3884774036ed14d40d84d285e4b43 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 19 Apr 2026 14:33:57 +0000 Subject: [PATCH] Write generated sources with UTF-8 charset FileWriter used the platform default charset, which produces non-portable output on systems where the default is not UTF-8 (e.g. Windows with a cp1252 default). Generated Java source should always be written as UTF-8. --- .../src/main/java/io/github/adamw7/tools/code/gen/Code.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/protogen-maven-plugin/src/main/java/io/github/adamw7/tools/code/gen/Code.java b/code/protogen-maven-plugin/src/main/java/io/github/adamw7/tools/code/gen/Code.java index a756da6..8daf087 100644 --- a/code/protogen-maven-plugin/src/main/java/io/github/adamw7/tools/code/gen/Code.java +++ b/code/protogen-maven-plugin/src/main/java/io/github/adamw7/tools/code/gen/Code.java @@ -1,11 +1,12 @@ package io.github.adamw7.tools.code.gen; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.io.UncheckedIOException; +import java.io.Writer; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -68,7 +69,7 @@ public void genBuilders(Set> allMessages) { private void write(ClassContainer container) { String fileName = generatedSourcesDir + replace(outputPkg + File.separator + container.name()) + ".java"; - try (FileWriter myWriter = new FileWriter(fileName)) { + try (Writer myWriter = Files.newBufferedWriter(Paths.get(fileName), StandardCharsets.UTF_8)) { log.info("Writing {}", fileName); myWriter.write(container.codeAsString()); } catch (IOException e) {