From 192dffb2693d0d5f47d7326214b2ab7d1a20b305 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Wed, 24 May 2023 20:10:27 +0200 Subject: [PATCH] Fix unmodifable Set Exception in generating preview Add hint in javadoc Fixes #9947 Fixes https://github.com/JabRef/jabref-issue-melting-pot/issues/183 --- CHANGELOG.md | 1 + .../jabref/logic/citationstyle/JabRefItemDataProvider.java | 3 ++- src/main/java/org/jabref/model/entry/BibEntry.java | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 894ddc88497..7812dc5e370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue in the preferences where custom columns could be added to the entry table with no qualifier. [#9913](https://github.com/JabRef/jabref/issues/9913) - We fixed an issue where the encoding header in a bib file was not respected when the file contained a BOM (Byte Order Mark). [#9926](https://github.com/JabRef/jabref/issues/9926) - We fixed an issue where cli help output for import and export format was inconsistent. [koppor#429](https://github.com/koppor/jabref/issues/429) +- We fixed an issue where no preview could be generated for some entry types and led to an exception [#9947](https://github.com/JabRef/jabref/issues/9947) ### Removed diff --git a/src/main/java/org/jabref/logic/citationstyle/JabRefItemDataProvider.java b/src/main/java/org/jabref/logic/citationstyle/JabRefItemDataProvider.java index b15c0e4534a..e75b4e7b3a9 100644 --- a/src/main/java/org/jabref/logic/citationstyle/JabRefItemDataProvider.java +++ b/src/main/java/org/jabref/logic/citationstyle/JabRefItemDataProvider.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Optional; @@ -147,7 +148,7 @@ private CSLItemData bibEntryToCSLItemData(BibEntry originalBibEntry, BibDatabase } } - Set fields = entryType.map(BibEntryType::getAllFields).orElse(bibEntry.getFields()); + Set fields = new LinkedHashSet<>(entryType.map(BibEntryType::getAllFields).orElse(bibEntry.getFields())); fields.addAll(bibEntry.getFields()); for (Field key : fields) { bibEntry.getResolvedFieldOrAlias(key, bibDatabaseContext.getDatabase()) diff --git a/src/main/java/org/jabref/model/entry/BibEntry.java b/src/main/java/org/jabref/model/entry/BibEntry.java index 4718ab3645a..29873c4d9c2 100644 --- a/src/main/java/org/jabref/model/entry/BibEntry.java +++ b/src/main/java/org/jabref/model/entry/BibEntry.java @@ -313,7 +313,7 @@ public Optional getResolvedFieldOrAliasLatexFree(Field field, BibDatabas } private Optional genericGetResolvedFieldOrAlias(Field field, BibDatabase database, BiFunction> getFieldOrAlias) { - if (InternalField.TYPE_HEADER == field || InternalField.OBSOLETE_TYPE_HEADER == field) { + if ((InternalField.TYPE_HEADER == field) || (InternalField.OBSOLETE_TYPE_HEADER == field)) { return Optional.of(type.get().getDisplayName()); } @@ -434,7 +434,7 @@ public Optional setType(EntryType newType, EntriesEventSource event } /** - * Returns a set containing the names of all fields that are set for this particular entry. + * Returns an {@link Collections#unmodifiableSet(Set)} containing the names of all fields that are set for this particular entry. * * @return a set of existing field names */ @@ -489,7 +489,7 @@ private Optional genericGetFieldOrAlias(Field field, BiFunction date = getFieldValue.apply(this, StandardField.DATE); if (date.isEmpty()) { return Optional.empty();