I have a Spring Boot application in which the underlying tomcat regularly throws an error like this:
2024-06-11 11:12:40,529 ERROR [http-nio-9312-exec-5] <org.apache.juli.logging.DirectJDKLog>: Error processing request
java.io.UncheckedIOException: Cannot delete C:WindowsTemptomcat.9312.3138704811626004803workTomcatlocalhostROOTupload_f2043be0_7945_4211_b735_367546c4255b_00000000.tmp
at org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.delete(DiskFileItem.java:429)
[...]
2024-06-11 11:12:40,536 ERROR [http-nio-9312-exec-5] <org.apache.juli.logging.DirectJDKLog>: Error reading request, ignored
java.io.UncheckedIOException: Cannot delete C:WindowsTemptomcat.9312.3138704811626004803workTomcatlocalhostROOTupload_f2043be0_7945_4211_b735_367546c4255b_00000000.tmp
at org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.delete(DiskFileItem.java:429)
[...]
2024-06-11 11:12:40,537 ERROR [http-nio-9312-exec-5] <org.apache.juli.logging.DirectJDKLog>: Error running socket processor
java.io.UncheckedIOException: Cannot delete C:WindowsTemptomcat.9312.3138704811626004803workTomcatlocalhostROOTupload_f2043be0_7945_4211_b735_367546c4255b_00000000.tmp
at org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.delete(DiskFileItem.java:429)
[...]
I have checked, and while the Folder C:WindowsTemptomcat.9312.3138704811626004803workTomcatlocalhostROOT
exists, the file upload_f2043be0_7945_4211_b735_367546c4255b_00000000.tmp
does not.
I have already tried setting spring.servlet.multipart.location
to a less protected location, but the same error still occurred in that case. What’s more, in that case it resulted in files and folders that I could not even delete with administrator rights.
This happens when the following endpoint is called:
@PostMapping(
value = "/validate",
consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
public ValidationResponse validateUploadedFile(
@RequestParam("file") MultipartFile file
) {
try {
validator.validateMultipartFile(file);
return ValidationResponse.buildValidResponse();
} catch (ValidationFailedException e) {
return ValidationResponse.buildValidationFailedResponse(e);
} catch (Exception e) {
return ValidationResponse.buildInvalidResponse(
"Unexpected exception occurred while trying to validate file: <"
+ e.getClass()
+ "> "
+ e.getMessage()
);
}
}
The funny thing is that the request always passes, so whatever this exception is, it appears afterwards, and I have no idea what to do about it.
Does anyone have any suggestions? I am using Spring Boot Version 3.3.0