WW-5616 - JakartaStreamMultiPartRequest warns on file delete if the file doesnt exist (#1591)

* Pull aspects into alignment with main/7.x+ AbstractMultiPartRequest.java
* Update JakartaMultiPartRequest and JakartaStreamMultiPartRequest to use isFile()
* Update cleanup text to mirror main/7.x+
This commit is contained in:
brianandle
2026-02-21 23:40:15 -08:00
committed by GitHub
parent 4b2915682d
commit d4a549672f
2 changed files with 18 additions and 8 deletions
@@ -373,10 +373,14 @@ public class JakartaMultiPartRequest extends AbstractMultiPartRequest {
if (item instanceof DiskFileItem) {
DiskFileItem diskItem = (DiskFileItem) item;
File storeLocation = diskItem.getStoreLocation();
if (storeLocation != null && storeLocation.exists()) {
LOG.debug("Deleting temporary file: [{}]", storeLocation.getName());
if (!storeLocation.delete()) {
LOG.warn("Unable to delete temporary file: [{}]", storeLocation.getName());
if (storeLocation != null) {
if(storeLocation.isFile()) {
LOG.debug("Deleting file: {}", storeLocation.getName());
if (!storeLocation.delete()) {
LOG.warn("There was a problem attempting to delete file: {}", storeLocation.getName());
}
} else {
LOG.debug("File: {} already deleted", storeLocation.getName());
}
}
}
@@ -79,10 +79,16 @@ public class JakartaStreamMultiPartRequest extends AbstractMultiPartRequest {
try {
// catch any exceptions during cleanup to ensure all files are deleted.
File file = fileInfo.getFile();
LOG.debug("Deleting file '{}'.", file.getName());
if (!file.delete()) {
LOG.warn("There was a problem attempting to delete file [{}].",
file.getName());
if(file != null) {
if(file.isFile()) {
LOG.debug("Deleting file: {}", file.getName());
if (!file.delete()) {
LOG.warn("There was a problem attempting to delete file: {}",
file.getName());
}
} else {
LOG.debug("File: {} already deleted", file.getName());
}
}
} catch (Exception e) {
LOG.warn("Error during cleanup of file item: [{}]", normalizeSpace(fileInfo.getOriginalName()), e);