Merge commit '77d3a60869e7a780c6ae069e51530e1eacece5e2'
[fanfix.git] / src / jexer / ttree / TDirectoryTreeItem.java
index c260d7fb95212c7920fce537f5deb74066553b9f..9bdec01dffd3cf51aeb5a233768b03e2f2b4e8e4 100644 (file)
@@ -3,7 +3,7 @@
  *
  * The MIT License (MIT)
  *
- * Copyright (C) 2017 Kevin Lamonte
+ * Copyright (C) 2019 Kevin Lamonte
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -35,7 +35,6 @@ import java.util.List;
 import java.util.LinkedList;
 
 import jexer.TWidget;
-import jexer.ttree.TTreeViewWidget;
 
 /**
  * TDirectoryTreeItem is a single item in a disk directory tree view.
@@ -182,25 +181,28 @@ public class TDirectoryTreeItem extends TTreeItem {
             return;
         }
 
-        for (File f: file.listFiles()) {
-            // System.err.printf("   -> file %s %s\n", file, file.getName());
+        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;
-            }
+                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());