Crash log: The NPE was able to escape, so catch it!

This commit is contained in:
Duy Tran Khanh 2022-04-01 20:47:23 +07:00 committed by GitHub
parent 252b5e0471
commit 0338bdcb36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -663,19 +663,21 @@ public final class Tools {
File fl = new File(dir);
File[] files = fl.listFiles(File::isFile);
if (files == null) {
return null;
}
long lastMod = Long.MIN_VALUE;
File choice = null;
for (File file : files) {
if (file.lastModified() > lastMod) {
choice = file;
lastMod = file.lastModified();
try {
for (File file : files) {
if (file.lastModified() > lastMod) {
choice = file;
lastMod = file.lastModified();
}
}
} catch (NullPointerException e) {
// fine, let's just return null
// if (files == null) didn't work for some reasons
e.printStackTrace();
}
return choice;
}