From 270691b63cab97f17071630ccb84b2d0dd92af69 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Sat, 7 Apr 2018 12:44:01 -0400 Subject: [PATCH] #30 fix potential NPE --- src/jexer/ttree/TDirectoryTreeItem.java | 37 +++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/jexer/ttree/TDirectoryTreeItem.java b/src/jexer/ttree/TDirectoryTreeItem.java index c260d7f..8c54b38 100644 --- a/src/jexer/ttree/TDirectoryTreeItem.java +++ b/src/jexer/ttree/TDirectoryTreeItem.java @@ -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()); -- 2.27.0