[
https://issues.apache.org/jira/browse/TIKA-4704?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18069900#comment-18069900
]
ASF GitHub Bot commented on TIKA-4704:
--------------------------------------
Copilot commented on code in PR #2727:
URL: https://github.com/apache/tika/pull/2727#discussion_r3015364218
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-zip-commons/src/test/java/org/apache/tika/detect/zip/ZipDetectionTest.java:
##########
@@ -79,7 +80,8 @@ public void testStreaming() throws Exception {
detector = new DefaultZipContainerDetector();
//try on a file that isn't a TikaInputStream
- try (InputStream is = new
BufferedInputStream(Files.newInputStream(TikaInputStream.get(getStream("testJAR.jar")).getPath())))
{
+ try (TemporaryResources tmp = new TemporaryResources();
+ InputStream is = new
BufferedInputStream(Files.newInputStream(TikaInputStream.get(getStream("testJAR.jar"),
tmp, new Metadata()).getPath()))) {
Review Comment:
`TikaInputStream.get(stream, tmp, metadata)` is explicitly documented to
*not* close the original `stream` when `TemporaryResources.close()` is called.
In this test, the `InputStream` returned by `getStream("testJAR.jar")` (and the
internal wrapper that would close it) is never closed because the
`TikaInputStream` instance is only used transiently for `getPath()` and is not
closed. This can still leak the underlying stream/file handle.
Consider creating a named `TikaInputStream` and including it in the
try-with-resources (alongside `tmp` and the file-based `is`), or otherwise
explicitly closing the `TikaInputStream`/original stream after `getPath()` is
obtained.
```suggestion
TikaInputStream tis =
TikaInputStream.get(getStream("testJAR.jar"), tmp, new Metadata());
InputStream is = new
BufferedInputStream(Files.newInputStream(tis.getPath()))) {
```
> Avoid remaining temp files
> --------------------------
>
> Key: TIKA-4704
> URL: https://issues.apache.org/jira/browse/TIKA-4704
> Project: Tika
> Issue Type: Task
> Affects Versions: 3.3.0
> Reporter: Tilman Hausherr
> Priority: Minor
> Fix For: 4.0.0, 3.3.1
>
> Attachments: screenshot-1.png
>
>
> This is my temp directory after a successful build of tika 3. We should try
> to lessen this.
> !screenshot-1.png!
--
This message was sent by Atlassian Jira
(v8.20.10#820010)