Cleanup: Fix potential NPE in Updater

This commit is contained in:
Phoenix616 2023-03-01 18:34:21 +01:00
parent 92a013dd10
commit 385672ecd4
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
1 changed files with 19 additions and 14 deletions

View File

@ -393,9 +393,12 @@ public final class Updater {
if (this.pluginFile(dFile.getName())) { if (this.pluginFile(dFile.getName())) {
final File oFile = new File(this.plugin.getDataFolder().getParent(), dFile.getName()); // Get current dir final File oFile = new File(this.plugin.getDataFolder().getParent(), dFile.getName()); // Get current dir
final File[] contents = oFile.listFiles(); // List of existing files in the current dir final File[] contents = oFile.listFiles(); // List of existing files in the current dir
for (final File cFile : dFile.listFiles()) // Loop through all the files in the new dir final File[] newFiles = dFile.listFiles();
if (newFiles != null) {
for (final File cFile : newFiles) // Loop through all the files in the new dir
{ {
boolean found = false; boolean found = false;
if (contents != null) {
for (final File xFile : contents) // Loop through contents to see if it exists for (final File xFile : contents) // Loop through contents to see if it exists
{ {
if (xFile.getName().equals(cFile.getName())) { if (xFile.getName().equals(cFile.getName())) {
@ -403,6 +406,7 @@ public final class Updater {
break; break;
} }
} }
}
if (!found) { if (!found) {
// Move the new file into the current dir // Move the new file into the current dir
cFile.renameTo(new File(oFile.getCanonicalFile() + File.separator + cFile.getName())); cFile.renameTo(new File(oFile.getCanonicalFile() + File.separator + cFile.getName()));
@ -413,6 +417,7 @@ public final class Updater {
} }
} }
} }
}
dFile.delete(); dFile.delete();
} }
} }