Skip to content

Commit b823795

Browse files
authored
Merge branch 'main' into fix-12810-escape-keyword-separators
2 parents 47934b0 + af362ea commit b823795

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
import org.jabref.model.database.BibDatabaseContext;
3737
import org.jabref.model.entry.BibEntryTypesManager;
3838

39-
import com.airhacks.afterburner.injection.Injector;
40-
4139
public class StyleSelectDialogViewModel {
4240

4341
private final DialogService dialogService;
@@ -49,6 +47,8 @@ public class StyleSelectDialogViewModel {
4947
private final FilePreferences filePreferences;
5048
private final OpenOfficePreferences openOfficePreferences;
5149

50+
private final BibEntryTypesManager bibEntryTypesManager;
51+
5252
private final ObjectProperty<Tab> selectedTab = new SimpleObjectProperty<>();
5353

5454
private final ListProperty<JStyleSelectViewModel> jStyles = new SimpleListProperty<>(FXCollections.observableArrayList());
@@ -73,6 +73,8 @@ public StyleSelectDialogViewModel(DialogService dialogService,
7373
this.filePreferences = preferences.getFilePreferences();
7474
this.openOfficePreferences = preferences.getOpenOfficePreferences();
7575

76+
this.bibEntryTypesManager = bibEntryTypesManager;
77+
7678
jStyles.addAll(loadJStyles());
7779

7880
OOStyle currentStyle = openOfficePreferences.getCurrentStyle();
@@ -198,7 +200,7 @@ public void addCslStyleFile() {
198200

199201
List<CitationStyle> allStyles = CSLStyleLoader.getStyles();
200202
List<CitationStylePreviewLayout> updatedLayouts = allStyles.stream()
201-
.map(style -> new CitationStylePreviewLayout(style, Injector.instantiateModelOrService(BibEntryTypesManager.class)))
203+
.map(style -> new CitationStylePreviewLayout(style, bibEntryTypesManager))
202204
.toList();
203205

204206
availableCslLayouts.setAll(updatedLayouts);

src/main/java/org/jabref/model/database/BibDatabase.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
import com.google.common.eventbus.EventBus;
4343
import com.google.common.eventbus.Subscribe;
44+
import org.jspecify.annotations.Nullable;
4445
import org.slf4j.Logger;
4546
import org.slf4j.LoggerFactory;
4647

@@ -233,7 +234,7 @@ public synchronized void removeEntries(List<BibEntry> toBeDeleted) {
233234
public synchronized void removeEntries(List<BibEntry> toBeDeleted, EntriesEventSource eventSource) {
234235
Objects.requireNonNull(toBeDeleted);
235236

236-
Collection idsToBeDeleted;
237+
Collection<String> idsToBeDeleted;
237238
if (toBeDeleted.size() > 10) {
238239
idsToBeDeleted = new HashSet<>();
239240
} else {
@@ -271,19 +272,20 @@ private void forEachCitationKey(BibEntry entry, Consumer<String> keyConsumer) {
271272
}
272273
}
273274

274-
public Set<BibEntry> getEntriesForCitationKey(String citationKey) {
275-
return citationIndex.getOrDefault(citationKey, Collections.emptySet());
275+
public Set<BibEntry> getEntriesForCitationKey(@Nullable String citationKey) {
276+
// explicit null check because citationIndex is a ConcurrentHashMap and will throw NPE on null
277+
return citationKey != null ? citationIndex.getOrDefault(citationKey, Collections.emptySet()) : Collections.emptySet();
276278
}
277279

278280
private Set<String> getReferencedCitationKeys(BibEntry entry) {
279281
Set<String> keys = new HashSet<>();
280-
forEachCitationKey(entry, key -> keys.add(key));
282+
forEachCitationKey(entry, keys::add);
281283
return keys;
282284
}
283285

284286
private void indexEntry(BibEntry entry) {
285287
forEachCitationKey(entry, key ->
286-
citationIndex.computeIfAbsent(key, k -> ConcurrentHashMap.newKeySet()).add(entry)
288+
citationIndex.computeIfAbsent(key, _ -> ConcurrentHashMap.newKeySet()).add(entry)
287289
);
288290
}
289291

@@ -514,9 +516,7 @@ private String resolveString(String label, Set<String> usedIds, Set<String> allU
514516
}
515517
// If not, log this string's ID now.
516518
usedIds.add(string.getId());
517-
if (allUsedIds != null) {
518-
allUsedIds.add(string.getId());
519-
}
519+
allUsedIds.add(string.getId());
520520

521521
// Ok, we found the string. Now we must make sure we
522522
// resolve any references to other strings in this one.

src/main/java/org/jabref/model/database/KeyChangeListener.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.jabref.model.entry.field.InternalField;
1515

1616
import com.google.common.eventbus.Subscribe;
17+
import org.jspecify.annotations.Nullable;
1718

1819
public class KeyChangeListener {
1920

@@ -41,7 +42,7 @@ public void listen(EntriesRemovedEvent event) {
4142
}
4243
}
4344

44-
private void updateEntryLinks(String newKey, String oldKey) {
45+
private void updateEntryLinks(String newKey, @Nullable String oldKey) {
4546
Set<BibEntry> affectedEntries = database.getEntriesForCitationKey(oldKey);
4647
for (BibEntry entry : affectedEntries) {
4748
entry.getFields(field -> field.getProperties().contains(FieldProperty.SINGLE_ENTRY_LINK))

0 commit comments

Comments
 (0)