Skip to content

Commit 8738e39

Browse files
committed
Check the return value of File.delete()
Check the return value of File.delete() and throw an exception if deleting a file fails.
1 parent ee5827a commit 8738e39

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@ public void close() {
270270
state.close();
271271
if (state.linesWritten == 0 && shouldDeleteIfEmpty) {
272272
try {
273-
resource.getFile().delete();
273+
if (!resource.getFile().delete()) {
274+
throw new ItemStreamException("Failed to delete empty file on close");
275+
}
274276
}
275277
catch (IOException e) {
276278
throw new ItemStreamException("Failed to delete empty file on close", e);

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,9 @@ public void close() {
735735
}
736736
if (currentRecordCount == 0 && shouldDeleteIfEmpty) {
737737
try {
738-
resource.getFile().delete();
738+
if (!resource.getFile().delete()) {
739+
throw new ItemStreamException("Failed to delete empty file on close");
740+
}
739741
}
740742
catch (IOException e) {
741743
throw new ItemStreamException("Failed to delete empty file on close", e);

0 commit comments

Comments
 (0)