Copilot commented on code in PR #434:
URL: 
https://github.com/apache/jackrabbit-filevault/pull/434#discussion_r4120037757


##########
vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageImpl.java:
##########
@@ -321,23 +321,18 @@ protected VaultPackage getPackage(boolean 
forceFileArchive) throws RepositoryExc
                     throw new IOException("Error while reading stream", e);
                 }
             } else {
+                Binary bin = getData().getBinary();
                 File tmpFile = File.createTempFile("vaultpack", ".zip");
-                // make sure the temp file is removed at the latest when the 
JVM terminates,
-                // in case it is never explicitly closed via 
ZipArchive.close()/ZipVaultPackage.close()
-                tmpFile.deleteOnExit();
-                try {
-                    Binary bin = getData().getBinary();
-                    try (FileOutputStream out = 
FileUtils.openOutputStream(tmpFile);
-                            InputStream in = bin.getStream()) {
-                        IOUtils.copy(in, out);
-                    } finally {
-                        bin.dispose();
-                    }
-                    pack = new ZipVaultPackage(tmpFile, true);
-                } catch (RepositoryException | IOException | RuntimeException 
e) {
-                    FileUtils.deleteQuietly(tmpFile);
+                try (FileOutputStream out = 
FileUtils.openOutputStream(tmpFile);
+                        InputStream in = bin.getStream()) {
+                    IOUtils.copy(in, out);
+                } catch (IOException e) {
+                    tmpFile.delete();
                     throw e;
+                } finally {
+                    bin.dispose();
                 }
+                pack = new ZipVaultPackage(tmpFile, true);

Review Comment:
   The cleanup scope is now too narrow for the temporary file lifecycle. If 
`File.createTempFile` fails, the already-acquired `Binary` is never disposed; 
if `getStream()`, the copy/close operations, or `new ZipVaultPackage(...)` 
raises a `RuntimeException`, the temp file is left behind before any 
archive/CloseWatcher exists to remove it. Keep temp-file creation, binary 
disposal, package construction, and cleanup in one structured try/catch/finally 
so every failure path releases both resources.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to