|
41 | 41 |
|
42 | 42 | import com.google.common.eventbus.EventBus; |
43 | 43 | import com.google.common.eventbus.Subscribe; |
| 44 | +import org.jspecify.annotations.Nullable; |
44 | 45 | import org.slf4j.Logger; |
45 | 46 | import org.slf4j.LoggerFactory; |
46 | 47 |
|
@@ -233,7 +234,7 @@ public synchronized void removeEntries(List<BibEntry> toBeDeleted) { |
233 | 234 | public synchronized void removeEntries(List<BibEntry> toBeDeleted, EntriesEventSource eventSource) { |
234 | 235 | Objects.requireNonNull(toBeDeleted); |
235 | 236 |
|
236 | | - Collection idsToBeDeleted; |
| 237 | + Collection<String> idsToBeDeleted; |
237 | 238 | if (toBeDeleted.size() > 10) { |
238 | 239 | idsToBeDeleted = new HashSet<>(); |
239 | 240 | } else { |
@@ -271,19 +272,20 @@ private void forEachCitationKey(BibEntry entry, Consumer<String> keyConsumer) { |
271 | 272 | } |
272 | 273 | } |
273 | 274 |
|
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(); |
276 | 278 | } |
277 | 279 |
|
278 | 280 | private Set<String> getReferencedCitationKeys(BibEntry entry) { |
279 | 281 | Set<String> keys = new HashSet<>(); |
280 | | - forEachCitationKey(entry, key -> keys.add(key)); |
| 282 | + forEachCitationKey(entry, keys::add); |
281 | 283 | return keys; |
282 | 284 | } |
283 | 285 |
|
284 | 286 | private void indexEntry(BibEntry entry) { |
285 | 287 | forEachCitationKey(entry, key -> |
286 | | - citationIndex.computeIfAbsent(key, k -> ConcurrentHashMap.newKeySet()).add(entry) |
| 288 | + citationIndex.computeIfAbsent(key, _ -> ConcurrentHashMap.newKeySet()).add(entry) |
287 | 289 | ); |
288 | 290 | } |
289 | 291 |
|
@@ -514,9 +516,7 @@ private String resolveString(String label, Set<String> usedIds, Set<String> allU |
514 | 516 | } |
515 | 517 | // If not, log this string's ID now. |
516 | 518 | usedIds.add(string.getId()); |
517 | | - if (allUsedIds != null) { |
518 | | - allUsedIds.add(string.getId()); |
519 | | - } |
| 519 | + allUsedIds.add(string.getId()); |
520 | 520 |
|
521 | 521 | // Ok, we found the string. Now we must make sure we |
522 | 522 | // resolve any references to other strings in this one. |
|
0 commit comments