You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ti...@apache.org on 2026/03/30 08:06:03 UTC
(tika) 01/01: [TIKA-4704] Close writer to avoid leak + use try-with-resources
This is an automated email from the ASF dual-hosted git repository.
tilman pushed a commit to branch TIKA-4704-1
in repository https://gitbox.apache.org/repos/asf/tika.git
commit 948a5493fa9aa6ded246b9f3eeb13b26626c5c76
Author: Tilman Hausherr <ti...@snafu.de>
AuthorDate: Mon Mar 30 10:05:53 2026 +0200
[TIKA-4704] Close writer to avoid leak + use try-with-resources
---
.../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,