[java] Reworking code to make it more readable and avoid potential NPE
@@ -100,18 +100,24 @@ private static URLClassLoader createExtendedClassLoader(String ext) {
List<File> jars = new ArrayList<>();
while (tokenizer.hasMoreTokens()) {
File file = new File(tokenizer.nextToken());
- if (file.exists()) {
+ if (!file.exists()) {
+ LOG.warning("WARNING: Extension file or directory does not exist: " + file);
+ continue;
+ }
+
if (file.isDirectory()) {
- for (File subdirFile : file.listFiles()) {
+ File[] files = file.listFiles();
+ if (files == null) {
+ LOG.warning("WARNING: Cannot list files in directory: " + file);
+ } else {
+ for (File subdirFile : files) {
if (subdirFile.isFile() && subdirFile.getName().endsWith(".jar")) {
jars.add(subdirFile);
}
}
- } else {
- jars.add(file);
}
} else {
- LOG.warning("WARNING: Extension file or directory does not exist: " + file);
+ jars.add(file);
}
}
