You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2026/10/20 21:06:24 UTC
(tomcat) 19/22: Do not swallow write failures when converting text files to HTML
This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 1f500d2041d0f6eadb29a0ebd155aaf2a4fba776
Author: opencode <re...@apache.org>
AuthorDate: Tue Oct 20 13:34:57 2026 +0200
Do not swallow write failures when converting text files to HTML
The converted pages were written through a PrintWriter, which swallows
IOExceptions raised by the underlying stream. A mid-stream write failure
such as a full disk was therefore silently ignored and the build
completed successfully with a truncated or empty .html file. Write
directly through an OutputStreamWriter instead, so write and close
failures propagate and are reported as a BuildException by the existing
error handling in execute(). The produced output is unchanged.
---
java/org/apache/tomcat/buildutil/Txt2Html.java | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/java/org/apache/tomcat/buildutil/Txt2Html.java b/java/org/apache/tomcat/buildutil/Txt2Html.java
index 60a3c46ddd..a08dd9c6f8 100644
--- a/java/org/apache/tomcat/buildutil/Txt2Html.java
+++ b/java/org/apache/tomcat/buildutil/Txt2Html.java
@@ -23,7 +23,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
+import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@@ -132,11 +132,10 @@ public class Txt2Html extends Task {
// Open files:
try (BufferedReader in =
new BufferedReader(new InputStreamReader(new FileInputStream(from), SOURCE_ENCODING))) {
- try (PrintWriter out =
- new PrintWriter(new OutputStreamWriter(new FileOutputStream(to), StandardCharsets.UTF_8))) {
+ try (Writer out = new OutputStreamWriter(new FileOutputStream(to), StandardCharsets.UTF_8)) {
// Output header:
- out.print("<!DOCTYPE html><html><head><meta charset=\"UTF-8\" />" +
+ out.write("<!DOCTYPE html><html><head><meta charset=\"UTF-8\" />" +
"<title>Source Code</title></head><body><pre>");
// Convert, line-by-line:
@@ -157,11 +156,11 @@ public class Txt2Html extends Task {
result.append(c);
}
}
- out.print(result.toString() + LINE_SEPARATOR);
+ out.write(result.toString() + LINE_SEPARATOR);
}
// Output footer:
- out.print("</pre></body></html>");
+ out.write("</pre></body></html>");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org