Skip to content

Commit 317d943

Browse files
committed
Use native encoding when writing the java arguments file
Closes gh-43051
1 parent 32c61a9 commit 317d943

File tree

1 file changed

+16
-1
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven

1 file changed

+16
-1
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.io.IOException;
2121
import java.net.MalformedURLException;
2222
import java.net.URL;
23+
import java.nio.charset.Charset;
24+
import java.nio.charset.UnsupportedCharsetException;
2325
import java.nio.file.Files;
2426
import java.nio.file.Path;
2527
import java.util.ArrayList;
@@ -469,7 +471,20 @@ static String format(String key, String value) {
469471
record ArgFile(Path path) {
470472

471473
private void write(CharSequence content) throws IOException {
472-
Files.writeString(this.path, "\"" + escape(content) + "\"");
474+
Files.writeString(this.path, "\"" + escape(content) + "\"", getCharset());
475+
}
476+
477+
private Charset getCharset() {
478+
String nativeEncoding = System.getProperty("native.encoding");
479+
if (nativeEncoding == null) {
480+
return Charset.defaultCharset();
481+
}
482+
try {
483+
return Charset.forName(nativeEncoding);
484+
}
485+
catch (UnsupportedCharsetException ex) {
486+
return Charset.defaultCharset();
487+
}
473488
}
474489

475490
private String escape(CharSequence content) {

0 commit comments

Comments
 (0)