void (@Nullable Object storage, @NotNull Path storageFile) { if (storage instanceof CleanableStorage) { try { ((CleanableStorage)storage).closeAndClean(); } catch (Throwable t) { LOG.info(storage.getClass().getSimpleName() + ".closeAndClean() fails: " + ExceptionUtil.getNonEmptyMessage(t, t.getClass().getSimpleName() + "(<no error message given>)")); } } else { LOG.info("[" + storageFile.getFileName() + "]: " + storage + " is not CleanableStorage " + "-> trying to clean by explicitly removing all the files [" + storageFile.getFileName() + "*]"); } //In theory, we should try removing files explicitly only as a last resort, if the code above fails // -- i.e. if .closeAndClean() fails, or storage is null, or not CleanableStorage... //In practice, though, I trust no one, not even JVM, nor my own code. Especially not my own code. // So let's do that always: boolean noSuchFilesRemains = IOUtil.deleteAllFilesStartingWith(storageFile); if (!noSuchFilesRemains) { LOG.info("Can't delete " + storageFile + "*"); } }