Fix potential NPE

Stacktrace:
java.lang.NullPointerException
    at net.filebot.util.PreferencesMap$StringAdapter.put(PreferencesMap.java:177)
    at net.filebot.util.PreferencesMap$StringAdapter.put(PreferencesMap.java:168)
    at net.filebot.util.PreferencesMap.put(PreferencesMap.java:37)
    at net.filebot.util.PreferencesList.setImpl(PreferencesList.java:63)
    at net.filebot.util.PreferencesList.copy(PreferencesList.java:97)
    at net.filebot.util.PreferencesList.remove(PreferencesList.java:74)
    at net.filebot.util.PreferencesList.trimToSize(PreferencesList.java:104)
    at net.filebot.util.PreferencesList.set(PreferencesList.java:111)
    at net.filebot.ui.rename.FormatDialog.lambda$new$17(FormatDialog.java:719)
    at net.filebot.util.ui.SwingUI$LambdaAction.actionPerformed(SwingUI.java:382)
    at net.filebot.ui.rename.RenamePanel.lambda$showFormatEditor$21(RenamePanel.java:585)
    at net.filebot.util.ui.SwingUI.withWaitCursor(SwingUI.java:327)
    at net.filebot.ui.rename.RenamePanel.showFormatEditor(RenamePanel.java:582)
    at net.filebot.ui.rename.RenamePanel.lambda$createFetchPopup$17(RenamePanel.java:472)
    at net.filebot.util.ui.SwingUI$LambdaAction.actionPerformed(SwingUI.java:382)
This commit is contained in:
Reinhard Pointner 2017-12-11 18:58:19 +01:00
parent d3c7028710
commit ee7c19d443
1 changed files with 5 additions and 11 deletions

View File

@ -2,6 +2,7 @@ package net.filebot.ui.rename;
import static java.awt.Font.*;
import static java.util.Collections.*;
import static java.util.stream.Collectors.*;
import static javax.swing.BorderFactory.*;
import static net.filebot.Logging.*;
import static net.filebot.Settings.*;
@ -23,6 +24,7 @@ import java.text.Format;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.TreeMap;
@ -703,20 +705,12 @@ public class FormatDialog extends JDialog {
// create new recent history and ignore duplicates
Set<String> recent = new LinkedHashSet<String>();
// add new format first
// remember the 8 most recent formats
recent.add(format.getExpression());
// save the 8 most recent formats
for (String expression : mode.persistentFormatHistory()) {
recent.add(expression);
if (recent.size() >= 8) {
break;
}
}
recent.addAll(mode.persistentFormatHistory());
// update persistent history
mode.persistentFormatHistory().set(recent);
mode.persistentFormatHistory().set(recent.stream().filter(Objects::nonNull).limit(8).collect(toList()));
finish(true);
} catch (ScriptException e) {