From 0827fda189f2d03db83ecf1f445052ccfe8ca9af Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 23 Dec 2013 13:42:56 +0000 Subject: [PATCH] * fix NPE issue @see http://www.filebot.net/forums/viewtopic.php?f=6&t=1199&p=7243#p7243 --- .../rename/FilesListTransferablePolicy.java | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/source/net/sourceforge/filebot/ui/rename/FilesListTransferablePolicy.java b/source/net/sourceforge/filebot/ui/rename/FilesListTransferablePolicy.java index 6fe95270..a1c2a17b 100644 --- a/source/net/sourceforge/filebot/ui/rename/FilesListTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/rename/FilesListTransferablePolicy.java @@ -1,7 +1,5 @@ - package net.sourceforge.filebot.ui.rename; - import static java.util.Arrays.*; import static net.sourceforge.filebot.MediaTypes.*; import static net.sourceforge.filebot.ui.transfer.FileTransferable.*; @@ -20,29 +18,24 @@ import net.sourceforge.filebot.media.MediaDetection; import net.sourceforge.filebot.ui.transfer.FileTransferablePolicy; import net.sourceforge.tuned.FastFile; - class FilesListTransferablePolicy extends FileTransferablePolicy { - + private final List model; - - + public FilesListTransferablePolicy(List model) { this.model = model; } - - + @Override protected boolean accept(List files) { return true; } - - + @Override protected void clear() { model.clear(); } - - + @Override public void handleTransferable(Transferable tr, TransferAction action) throws Exception { if (action == TransferAction.LINK) { @@ -54,24 +47,22 @@ class FilesListTransferablePolicy extends FileTransferablePolicy { super.handleTransferable(tr, action); } } - - + @Override protected void load(List files) { load(files, true); } - - + protected void load(List files, boolean recursive) { List entries = new ArrayList(); LinkedList queue = new LinkedList(files); - + while (queue.size() > 0) { File f = queue.removeFirst(); - + if (f.isHidden()) continue; - + if (recursive && LIST_FILES.accept(f)) { // don't use new Scanner(File) because of BUG 6368019 (http://bugs.sun.com/view_bug.do?bug_id=6368019) try { @@ -87,7 +78,7 @@ class FilesListTransferablePolicy extends FileTransferablePolicy { } } scanner.close(); - + if (paths.isEmpty()) { entries.add(f); // treat as simple text file } else { @@ -98,18 +89,20 @@ class FilesListTransferablePolicy extends FileTransferablePolicy { } } else if (!recursive || f.isFile() || MediaDetection.isDiskFolder(f)) { entries.add(f); - } else { - queue.addAll(0, asList(f.listFiles())); + } else if (f.isDirectory()) { + File[] children = f.listFiles(); + if (children != null) { + queue.addAll(0, asList(children)); + } } } - + model.addAll(FastFile.foreach(entries)); } - - + @Override public String getFileFilterDescription() { return "files and folders"; } - + }