Skip to content

Commit ff28191

Browse files
committed
Pin charsets to UTF-8 in two test sites uncovered by charset audit
Audit of byte/char boundaries across all production and test source revealed two test-only sites with implicit charset dependencies: - ContentPartTest.imageFileRejectsUnknownExtension: replace Files.write(file, "hello".getBytes()) with Files.writeString(file, "hello"). The string is ASCII so byte output was identical everywhere today, but Files.writeString uses UTF-8 by contract (per JDK docs since Java 11) and the new form is shorter. - LlamaModelTest.completeAndReadStdOut: pin the PrintStream that captures System.out and the matching ByteArrayOutputStream.toString to StandardCharsets.UTF_8. Model output is multi-byte UTF-8 token text; on a non-UTF-8 default host (e.g. Windows CP-1252) the captured assertion strings would mangle non-ASCII tokens. Removes the stale @SuppressWarnings('ImplicitDefaultCharsetUsage'). Spotbugs count unchanged at 0. Tests pass cleanly through the charset-pinned capture path.
1 parent 4ace716 commit ff28191

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/test/java/net/ladenthin/llama/ContentPartTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void imageFileDetectsGif() throws IOException {
116116
@Test
117117
public void imageFileRejectsUnknownExtension() throws IOException {
118118
Path file = tmp.resolve("doc.txt");
119-
Files.write(file, "hello".getBytes());
119+
Files.writeString(file, "hello");
120120
try {
121121
ContentPart.imageFile(file);
122122
fail("expected IllegalArgumentException for unknown extension");

src/test/java/net/ladenthin/llama/LlamaModelTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.junit.jupiter.api.Assertions.*;
99

1010
import java.io.*;
11+
import java.nio.charset.StandardCharsets;
1112
import java.util.*;
1213
import java.util.regex.Pattern;
1314
import net.ladenthin.llama.args.LogFormat;
@@ -608,8 +609,7 @@ public void testLogStdout() {
608609
private String completeAndReadStdOut() {
609610
PrintStream stdOut = System.out;
610611
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
611-
@SuppressWarnings("ImplicitDefaultCharsetUsage")
612-
PrintStream printStream = new PrintStream(outputStream);
612+
PrintStream printStream = new PrintStream(outputStream, false, StandardCharsets.UTF_8);
613613
System.setOut(printStream);
614614

615615
try {
@@ -622,7 +622,7 @@ private String completeAndReadStdOut() {
622622
printStream.close();
623623
}
624624

625-
return outputStream.toString();
625+
return outputStream.toString(StandardCharsets.UTF_8);
626626
}
627627

628628
private List<String> splitLines(String text) {

0 commit comments

Comments
 (0)