* fix NPE issue

@see http://www.filebot.net/forums/viewtopic.php?f=6&t=1199&p=7243#p7243
This commit is contained in:
Reinhard Pointner 2013-12-23 13:42:56 +00:00
parent f5910f837d
commit 0827fda189
1 changed files with 19 additions and 26 deletions

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot.ui.rename; package net.sourceforge.filebot.ui.rename;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static net.sourceforge.filebot.MediaTypes.*; import static net.sourceforge.filebot.MediaTypes.*;
import static net.sourceforge.filebot.ui.transfer.FileTransferable.*; 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.filebot.ui.transfer.FileTransferablePolicy;
import net.sourceforge.tuned.FastFile; import net.sourceforge.tuned.FastFile;
class FilesListTransferablePolicy extends FileTransferablePolicy { class FilesListTransferablePolicy extends FileTransferablePolicy {
private final List<File> model; private final List<File> model;
public FilesListTransferablePolicy(List<File> model) { public FilesListTransferablePolicy(List<File> model) {
this.model = model; this.model = model;
} }
@Override @Override
protected boolean accept(List<File> files) { protected boolean accept(List<File> files) {
return true; return true;
} }
@Override @Override
protected void clear() { protected void clear() {
model.clear(); model.clear();
} }
@Override @Override
public void handleTransferable(Transferable tr, TransferAction action) throws Exception { public void handleTransferable(Transferable tr, TransferAction action) throws Exception {
if (action == TransferAction.LINK) { if (action == TransferAction.LINK) {
@ -55,13 +48,11 @@ class FilesListTransferablePolicy extends FileTransferablePolicy {
} }
} }
@Override @Override
protected void load(List<File> files) { protected void load(List<File> files) {
load(files, true); load(files, true);
} }
protected void load(List<File> files, boolean recursive) { protected void load(List<File> files, boolean recursive) {
List<File> entries = new ArrayList<File>(); List<File> entries = new ArrayList<File>();
LinkedList<File> queue = new LinkedList<File>(files); LinkedList<File> queue = new LinkedList<File>(files);
@ -98,15 +89,17 @@ class FilesListTransferablePolicy extends FileTransferablePolicy {
} }
} else if (!recursive || f.isFile() || MediaDetection.isDiskFolder(f)) { } else if (!recursive || f.isFile() || MediaDetection.isDiskFolder(f)) {
entries.add(f); entries.add(f);
} else { } else if (f.isDirectory()) {
queue.addAll(0, asList(f.listFiles())); File[] children = f.listFiles();
if (children != null) {
queue.addAll(0, asList(children));
}
} }
} }
model.addAll(FastFile.foreach(entries)); model.addAll(FastFile.foreach(entries));
} }
@Override @Override
public String getFileFilterDescription() { public String getFileFilterDescription() {
return "files and folders"; return "files and folders";