[ 
https://issues.apache.org/jira/browse/TIKA-4704?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18069385#comment-18069385
 ] 

ASF GitHub Bot commented on TIKA-4704:
--------------------------------------

Copilot commented on code in PR #2717:
URL: https://github.com/apache/tika/pull/2717#discussion_r3006189191


##########
tika-core/src/main/java/org/apache/tika/fork/ForkClient.java:
##########
@@ -324,6 +324,7 @@ public synchronized void close() {
         }
         if (jar != null) {
             jar.delete();
+            jar.deleteOnExit();

Review Comment:
   `File#deleteOnExit()` can throw `SecurityException`. Since `close()` 
currently doesn’t declare/expect to throw and is used in failure-cleanup paths, 
this new call can cause unexpected runtime failure during cleanup. Please guard 
the `deleteOnExit()` call (and any conditional logic around it) to keep 
`close()` best-effort.
   ```suggestion
               try {
                   jar.deleteOnExit();
               } catch (SecurityException ignore) {
                   // best-effort cleanup; ignore inability to register 
deleteOnExit
               }
   ```



##########
tika-core/src/main/java/org/apache/tika/fork/ForkClient.java:
##########
@@ -324,6 +324,7 @@ public synchronized void close() {
         }
         if (jar != null) {
             jar.delete();
+            jar.deleteOnExit();

Review Comment:
   `deleteOnExit()` is currently registered unconditionally. Even when 
`jar.delete()` succeeds, `deleteOnExit()` still adds the path to the JVM’s 
global delete-on-exit list, which can grow over time in long-running processes 
and provides no benefit after a successful delete. Consider checking the 
boolean result of `jar.delete()` (or using `Files.delete`/`deleteIfExists`) and 
only calling `deleteOnExit()` when the immediate deletion fails (optionally log 
that failure, similar to `TemporaryResources#createTempFile`).
   ```suggestion
               if (!jar.delete()) {
                   jar.deleteOnExit();
               }
   ```





> 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)

Reply via email to