#30 fix potential NPE
authorKevin Lamonte <kevin.lamonte@gmail.com>
Sat, 7 Apr 2018 16:44:01 +0000 (12:44 -0400)
committerKevin Lamonte <kevin.lamonte@gmail.com>
Sat, 7 Apr 2018 16:44:01 +0000 (12:44 -0400)
src/jexer/ttree/TDirectoryTreeItem.java

index c260d7fb95212c7920fce537f5deb74066553b9f..8c54b386753e60b1a6f8c70d35170126fd7c6cbc 100644 (file)
@@ -182,25 +182,28 @@ public class TDirectoryTreeItem extends TTreeItem {
             return;
         }
 
-        for (File f: file.listFiles()) {
-            // System.err.printf("   -> file %s %s\n", file, file.getName());
-
-            if (f.getName().startsWith(".")) {
-                // Hide dot-files
-                continue;
-            }
-            if (!f.isDirectory()) {
-                continue;
-            }
+        File [] listFiles = file.listFiles();
+        if (listFiles != null) {
+            for (File f: listFiles) {
+                // System.err.printf("   -> file %s %s\n", file, file.getName());
+
+                if (f.getName().startsWith(".")) {
+                    // Hide dot-files
+                    continue;
+                }
+                if (!f.isDirectory()) {
+                    continue;
+                }
 
-            try {
-                TDirectoryTreeItem item = new TDirectoryTreeItem(treeViewWidget,
-                    f.getCanonicalPath(), false, false);
+                try {
+                    TDirectoryTreeItem item = new TDirectoryTreeItem(treeViewWidget,
+                        f.getCanonicalPath(), false, false);
 
-                item.level = this.level + 1;
-                getChildren().add(item);
-            } catch (IOException e) {
-                continue;
+                    item.level = this.level + 1;
+                    getChildren().add(item);
+                } catch (IOException e) {
+                    continue;
+                }
             }
         }
         Collections.sort(getChildren());