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

tilman pushed a commit to branch branch_3x
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/branch_3x by this push:
     new b01874f185 [TIKA-4704] Close writer to avoid leak + use 
try-with-resources (#2722)
b01874f185 is described below

commit b01874f185e3f7449c25a4636889ebb2cd7713d3
Author: Tilman Hausherr <[email protected]>
AuthorDate: Mon Mar 30 10:33:56 2026 +0200

    [TIKA-4704] Close writer to avoid leak + use try-with-resources (#2722)
---
 .../java/org/apache/tika/pipes/grpc/TikaGrpcServerImpl.java | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git 
a/tika-grpc/src/main/java/org/apache/tika/pipes/grpc/TikaGrpcServerImpl.java 
b/tika-grpc/src/main/java/org/apache/tika/pipes/grpc/TikaGrpcServerImpl.java
index cd8ed80505..fccd1def5e 100644
--- a/tika-grpc/src/main/java/org/apache/tika/pipes/grpc/TikaGrpcServerImpl.java
+++ b/tika-grpc/src/main/java/org/apache/tika/pipes/grpc/TikaGrpcServerImpl.java
@@ -19,6 +19,7 @@ package org.apache.tika.pipes.grpc;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.Writer;
 import java.lang.reflect.InvocationTargetException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
@@ -153,12 +154,14 @@ class TikaGrpcServerImpl extends TikaGrpc.TikaImplBase {
             fetchersElement.appendChild(fetcher);
         }
         DOMSource source = new DOMSource(tikaConfigDoc);
-        FileWriter writer = new FileWriter(tikaConfigPath, 
StandardCharsets.UTF_8);
-        StreamResult result = new StreamResult(writer);
+        try (Writer writer = new FileWriter(tikaConfigPath, 
StandardCharsets.UTF_8))
+        {
+            StreamResult result = new StreamResult(writer);
 
-        TransformerFactory transformerFactory = 
XMLReaderUtils.getTransformerFactory();
-        Transformer transformer = transformerFactory.newTransformer();
-        transformer.transform(source, result);
+            TransformerFactory transformerFactory = 
XMLReaderUtils.getTransformerFactory();
+            Transformer transformer = transformerFactory.newTransformer();
+            transformer.transform(source, result);
+        }
     }
 
     private void populateFetcherConfigs(Map<String, Object> 
fetcherConfigParams,

Reply via email to