Skip to content

Commit

Permalink
Fix freezing when fetching IBSN and no results are found (#9987)
Browse files Browse the repository at this point in the history
* Fix freezing when fetching IBSN and no results are found

Fixes part of #9979

* Modernize IsbnFetcher

* Add missing dots

---------

Co-authored-by: Oliver Kopp <[email protected]>
  • Loading branch information
Siedlerchr and koppor authored Jun 8, 2023
1 parent 7d64663 commit ef6d4e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ 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)
- 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)
- We fixed an issue where the Linux terminal working directory argument was malformed and therefore ignored upon opening a terminal [#9953](https://github.com/JabRef/jabref/issues/9953)
- We fixen an issue under Linux where under some systems the file instead of the folder was opened [#9607](https://github.com/JabRef/jabref/issues/9607)
- We fixen an issue under Linux where under some systems the file instead of the folder was opened. [#9607](https://github.com/JabRef/jabref/issues/9607)
- We fixed an issue where an Automatic Keyword Group could not be deleted in the UI. [#9778](https://github.com/JabRef/jabref/issues/9778)
- We fixed an issue where the citation key pattern `[edtrN_M]` returned the wrong editor. [#9946](https://github.com/JabRef/jabref/pull/9946)
- We fixed an issue where empty grey containers would remain in the groups panel, if displaying of group item count is turned off [#9972](https://github.com/JabRef/jabref/issues/9972)
- We fixed an issue where empty grey containers would remain in the groups panel, if displaying of group item count is turned off. [#9972](https://github.com/JabRef/jabref/issues/9972)
- We fixed an issue where fetching an ISBN could lead to application freezing when the fetcher did not return any results. [#9979](https://github.com/JabRef/jabref/issues/9979)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -62,22 +64,23 @@ public Optional<BibEntry> performSearchById(String identifier) throws FetcherExc
identifier = removeNewlinesAndSpacesFromIdentifier(identifier);
bibEntry = openLibraryIsbnFetcher.performSearchById(identifier);
} catch (FetcherException ex) {
LOGGER.debug("Got a fetcher exception for IBSN search", ex);
if (retryIsbnFetcher.isEmpty()) {
throw ex;
} else {
LOGGER.debug("Got a fetcher exception for IBSN search", ex);
LOGGER.debug("Try using the alternate ISBN fetchers to find an entry.");
}
} finally {
while (bibEntry.isEmpty() && retryIsbnFetcher.iterator().hasNext()) {
AbstractIsbnFetcher fetcher = retryIsbnFetcher.iterator().next();
LOGGER.debug("No entry found for ISBN=" + identifier + "; trying " + fetcher.getName() + " next.");
LOGGER.debug("Trying using the alternate ISBN fetchers to find an entry.");
// do not move the iterator in the loop as this would always return a new one and thus create and endless loop
Iterator<AbstractIsbnFetcher> iterator = retryIsbnFetcher.iterator();
while (bibEntry.isEmpty() && iterator.hasNext()) {
AbstractIsbnFetcher fetcher = iterator.next();
LOGGER.debug("No entry found for ISBN {}; trying {} next.", identifier, fetcher.getName());
bibEntry = fetcher.performSearchById(identifier);
}
}

if (bibEntry.isEmpty()) {
LOGGER.debug("Could not found a entry for ISBN=" + identifier);
LOGGER.debug("Could not found a entry for ISBN {}", identifier);
}

return bibEntry;
Expand All @@ -94,9 +97,7 @@ public List<BibEntry> performSearch(BibEntry entry) throws FetcherException {
}

public IsbnFetcher addRetryFetcher(AbstractIsbnFetcher retryFetcher) {
if (retryFetcher == null) {
throw new IllegalArgumentException("Please provide a valid isbn fetcher.");
}
Objects.requireNonNull(retryFetcher, "Please provide a valid isbn fetcher.");
retryIsbnFetcher.add(retryFetcher);
return this;
}
Expand Down

0 comments on commit ef6d4e6

Please sign in to comment.