File::listFiles may return null, let's catch that potentional null pointer.

This commit is contained in:
Maschell 2019-02-28 10:03:11 +01:00
parent 73b6787c42
commit 6d98a8b92c

View File

@ -17,7 +17,6 @@
package de.mas.wiiu.jnus.utils; package de.mas.wiiu.jnus.utils;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -100,7 +99,7 @@ public final class FileUtils {
if (!filepath.exists()) { if (!filepath.exists()) {
// Try to find it ignoring cases. // Try to find it ignoring cases.
File[] filesIngoringCases = new File(folder).listFiles(f -> f.getName().equalsIgnoreCase(filename)); File[] filesIngoringCases = new File(folder).listFiles(f -> f.getName().equalsIgnoreCase(filename));
if (filesIngoringCases.length == 1 && !filesIngoringCases[0].isDirectory()) { if (filesIngoringCases != null && filesIngoringCases.length == 1 && !filesIngoringCases[0].isDirectory()) {
return filesIngoringCases[0].getAbsoluteFile(); return filesIngoringCases[0].getAbsoluteFile();
} else { } else {
return null; return null;