[Minor] Code cleanup

This commit is contained in:
Robert von Burg 2023-04-04 16:13:16 +02:00
parent 89dc892172
commit 79bc086e24
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
1 changed files with 9 additions and 6 deletions

View File

@ -85,10 +85,13 @@ public class XmlExportModelCommand extends Command {
private void cleanUpExisting(final String exportName) {
File parentFile = this.modelFile.getParentFile();
File[] existingFiles = parentFile.listFiles((dir, name) -> name.startsWith(exportName) && name.endsWith(".xml"));
for (File file : existingFiles) {
file.delete();
File[] existingFiles = parentFile.listFiles(
(dir, name) -> name.startsWith(exportName) && name.endsWith(".xml"));
if (existingFiles != null) {
for (File file : existingFiles) {
if (!file.delete())
throw new IllegalStateException("Failed to delete file " + file);
}
}
}
@ -253,8 +256,8 @@ public class XmlExportModelCommand extends Command {
} catch (Exception e) {
for (File createdFile : createdFiles) {
if (createdFile.exists())
createdFile.delete();
if (createdFile.exists() && !createdFile.delete())
throw new IllegalStateException("Failed to delete file " + createdFile);
}
String msg = "Failed to write model to file {0} due to {1}";
msg = MessageFormat.format(msg, this.modelFile, e.getMessage());