Log an error if a DeletingFileInputStream is open at finalization

This commit is contained in:
Michael Walker 2018-02-26 14:47:41 +00:00
parent 55cb41f5b2
commit ddc524b588

View file

@ -38,4 +38,23 @@ public class DeletingFileInputStream extends FileInputStream {
}
}
}
/**
* We shouldn't rely on this for correctness!
*/
@Override
protected void finalize() throws IOException {
try {
super.finalize();
} finally {
if(file != null) {
Log.warn("File open at finalization time: {}", file.getCanonicalPath());
try {
close();
} catch (IOException e) {
Log.error("Failed to delete file", e);
}
}
}
}
}