Check the return value of File.delete()

Check the return value of File.delete() and
throw an exception if deleting a file fails.

Issue #4203
This commit is contained in:
Philippe Marschall
2022-10-03 22:38:32 +02:00
committed by Mahmoud Ben Hassine
parent 15f3637ac8
commit 8c7fb5ca02
2 changed files with 8 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -270,7 +270,9 @@ public abstract class AbstractFileItemWriter<T> extends AbstractItemStreamItemWr
state.close();
if (state.linesWritten == 0 && shouldDeleteIfEmpty) {
try {
resource.getFile().delete();
if (!resource.getFile().delete()) {
throw new ItemStreamException("Failed to delete empty file on close");
}
}
catch (IOException e) {
throw new ItemStreamException("Failed to delete empty file on close", e);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -735,7 +735,9 @@ public class StaxEventItemWriter<T> extends AbstractItemStreamItemWriter<T>
}
if (currentRecordCount == 0 && shouldDeleteIfEmpty) {
try {
resource.getFile().delete();
if (!resource.getFile().delete()) {
throw new ItemStreamException("Failed to delete empty file on close");
}
}
catch (IOException e) {
throw new ItemStreamException("Failed to delete empty file on close", e);