This is an automated email from the ASF dual-hosted git repository.

rmaucher pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 5edca2207aa62b50dc96cf7b10eefd45541ae2d2
Author: opencode <[email protected]>
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 | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/tomcat/buildutil/Txt2Html.java 
b/java/org/apache/tomcat/buildutil/Txt2Html.java
index 84fb7b9d5f..a61ab337df 100644
--- a/java/org/apache/tomcat/buildutil/Txt2Html.java
+++ b/java/org/apache/tomcat/buildutil/Txt2Html.java
@@ -24,6 +24,8 @@ 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;
 
@@ -131,10 +133,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), "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:
@@ -155,11 +157,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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to