Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookup filetypes in enum set to prevent NPE due to uninitialized expo… #3597

Merged
merged 3 commits into from
Jan 4, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/main/java/org/jabref/preferences/CustomExportList.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.jabref.preferences;

import java.util.Comparator;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.TreeMap;

import org.jabref.Globals;
import org.jabref.logic.exporter.Exporter;
import org.jabref.logic.exporter.SavePreferences;
import org.jabref.logic.exporter.TemplateExporter;
import org.jabref.logic.journals.JournalAbbreviationLoader;
Expand All @@ -31,21 +30,22 @@

public class CustomExportList {

private static EnumSet<FileType> allFiles = EnumSet.allOf(FileType.class);

private static final Log LOGGER = LogFactory.getLog(CustomExportList.class);
private final EventList<List<String>> list;
private final SortedList<List<String>> sorted;

private final Map<String, TemplateExporter> formats = new TreeMap<>();


public CustomExportList(Comparator<List<String>> comp) {
list = new BasicEventList<>();
sorted = new SortedList<>(list, comp);
}

private static FileType getFileExtension(String consoleName) {
Optional<Exporter> exporter = Globals.exportFactory.getExporterByName(consoleName);
return exporter.map(Exporter::getFileType).orElse(FileType.DEFAULT);
Optional<FileType> fileType = allFiles.stream().filter(f -> f.getExtensionsWithDot().stream().anyMatch(consoleName::equals)).findFirst();
return fileType.orElse(FileType.DEFAULT);
}

public int size() {
Expand All @@ -57,7 +57,7 @@ public EventList<List<String>> getSortedList() {
}

public Map<String, TemplateExporter> getCustomExportFormats(JabRefPreferences prefs,
JournalAbbreviationLoader loader) {
JournalAbbreviationLoader loader) {
Objects.requireNonNull(prefs);
Objects.requireNonNull(loader);
formats.clear();
Expand Down Expand Up @@ -88,7 +88,7 @@ private void readPrefs(JabRefPreferences prefs, JournalAbbreviationLoader loader
}

private Optional<TemplateExporter> createFormat(List<String> s, LayoutFormatterPreferences layoutPreferences,
SavePreferences savePreferences) {
SavePreferences savePreferences) {
if (s.size() < 3) {
return Optional.empty();
}
Expand Down Expand Up @@ -132,7 +132,7 @@ private void purge(int from, JabRefPreferences prefs) {
}

public void remove(List<String> toRemove, LayoutFormatterPreferences layoutPreferences,
SavePreferences savePreferences) {
SavePreferences savePreferences) {
createFormat(toRemove, layoutPreferences, savePreferences).ifPresent(format -> {
formats.remove(format.getId());
list.remove(toRemove);
Expand Down