Skip to content

Commit 9620991

Browse files
committed
Refuse a Java file that is not UTF-8 instead of rewriting it
new String(bytes, UTF_8) turned each byte that is not UTF-8 into U+FFFD, and --replace wrote the result back: an "é" saved as Latin-1 became EF BF BD, and the exit code was 0. Files.readString throws on such a byte, so the file is reported as one Main could not read and stays as it is, with exit code 2. Standard input still decodes with replacement.
1 parent dbd0dd7 commit 9620991

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • open-java-format/src/main/java/com/palantir/javaformat/java

‎open-java-format/src/main/java/com/palantir/javaformat/java/Main.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private int formatFiles(
146146
Path path = Paths.get(fileName);
147147
String input;
148148
try {
149-
input = new String(Files.readAllBytes(path), UTF_8);
149+
input = Files.readString(path);
150150
inputs.put(path, input);
151151
results.put(path, executorService.submit(new FormatFileCallable(parameters, input, options)));
152152
} catch (IOException e) {

0 commit comments

Comments
 (0)