Copilot commented on code in PR #560:
URL: https://github.com/apache/maven-ear-plugin/pull/560#discussion_r4360250438


##########
src/main/java/org/apache/maven/plugins/ear/EarMojo.java:
##########
@@ -886,7 +886,9 @@ private void deleteOutdatedResources(final 
Collection<String> outdatedResources)
             if (resourceFile.lastModified() < startTime) {
                 getLog().debug("deleting outdated resource " + 
outdatedResource);
                 getLog().debug(outdatedResource + " last modified: " + 
resourceFile.lastModified());
-                resourceFile.delete();
+                if (!resourceFile.delete()) {
+                    getLog().warn("Failed to delete outdated resource: " + 
resourceFile);
+                }
             }

Review Comment:
   `File.lastModified()` returns `0L` when the file does not exist, which will 
almost always be `< startTime`. That can cause a warning for resources that are 
already missing (delete returns false), introducing noisy/incorrect warnings. 
Consider gating the deletion path on `resourceFile.exists()` (before the 
last-modified comparison and/or before warning), or only emitting the warning 
when the file still exists after the delete attempt.



##########
src/main/java/org/apache/maven/plugins/ear/EarMojo.java:
##########
@@ -886,7 +886,9 @@ private void deleteOutdatedResources(final 
Collection<String> outdatedResources)
             if (resourceFile.lastModified() < startTime) {
                 getLog().debug("deleting outdated resource " + 
outdatedResource);
                 getLog().debug(outdatedResource + " last modified: " + 
resourceFile.lastModified());
-                resourceFile.delete();
+                if (!resourceFile.delete()) {
+                    getLog().warn("Failed to delete outdated resource: " + 
resourceFile);

Review Comment:
   `File.delete()` provides no failure details, and logging `resourceFile` may 
be a relative path, which can make the warning hard to act on. Consider logging 
`outdatedResource` and/or `resourceFile.getAbsolutePath()`; if you want 
actionable diagnostics, prefer `java.nio.file.Files.delete(...)` / 
`deleteIfExists(...)` so you can include the `IOException` message in the 
warning.



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