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

Seaching for bibliographies and importing them triggers uncaught java.lang.IndexOutOfBoundsException #7606

Closed
1 task done
sauliusg opened this issue Apr 4, 2021 · 4 comments · Fixed by #7672
Closed
1 task done
Labels
bug Confirmed bugs or reports that are very likely to be bugs cleanup-ops fetcher good first issue An issue intended for project-newcomers. Varies in difficulty.

Comments

@sauliusg
Copy link
Contributor

sauliusg commented Apr 4, 2021

JabRef version 5.2, 5.3, commit badffe9 in 'master' on LinuxMint-19.3, Linuxmint-20.1 -->

When search for literature (say in ArXiv) and the importing entries, an uncaught exception is triggered. This behaviour is not always present, but can be reproduced after searching and importing several times in the same session.

Steps to reproduce the behavior:

  1. Start a JabRef session without any databases;
  2. Create a new database;
  3. Save it under some name (e.g. 'test.bib'); this is essential, otherwise different exception is triggered;
  4. Open Groups interface (not clear if this is important, but I had it open during tests; also they are open in screens at Uncaught exception when searching in dark mode #7343)
  5. Open Web search interfacel
  6. Select arXive (possibly other search source would give the same behaviour);
  7. Search for "Minkowski space", receive 20 hits;
  8. select them all and import;
  9. If the exceeption is not trigegred immediately, repeat the steps 7-8 with other search terms, e.g. "Kilogram definition", "Teaching Temperature", etc.
  10. At some stage an exception window pops up:
    Screenshot from 2021-04-04 10-04-44

The bug might be related to #7343, but the exception is different (OutOfBounds instead NullPointer), and is not in the Dark mode.

Sometimes there are multiple exceptions happening opening multiple pop-up windows. The fate of JabRef after exception is different – sometimes it freezes and the process needs to be killed, sometimes one can still save the database after closing the exception popup. If JabRef can be closed via it interface, it reports numerous dowload threads still running in the bacground.

More screenshots with sporadic exceptions after the sequence of actions listed here are available in my server:
http://saulius-grazulis.lt/~saulius/JabRef/screenshots/

The log message, copied and pasted from the window, reads:

Log File
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
  at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
  at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
  at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
  at java.base/java.util.Objects.checkIndex(Objects.java:373)
  at java.base/java.util.ArrayList.get(ArrayList.java:427)
  at javafx.base/javafx.collections.ListChangeBuilder.insertUpdate(ListChangeBuilder.java:84)
  at javafx.base/javafx.collections.ListChangeBuilder.nextUpdate(ListChangeBuilder.java:467)
  at javafx.base/javafx.collections.ObservableListBase.nextUpdate(ObservableListBase.java:109)
  at javafx.base/com.sun.javafx.collections.ObservableListWrapper.access$100(ObservableListWrapper.java:45)
  at javafx.base/com.sun.javafx.collections.ObservableListWrapper$1$1.invalidated(ObservableListWrapper.java:72)
  at javafx.base/com.sun.javafx.collections.MapListenerHelper$SingleInvalidation.fireValueChangedEvent(MapListenerHelper.java:125)
  at javafx.base/com.sun.javafx.collections.MapListenerHelper.fireValueChangedEvent(MapListenerHelper.java:72)
  at javafx.base/com.sun.javafx.collections.ObservableMapWrapper.callObservers(ObservableMapWrapper.java:115)
  at javafx.base/com.sun.javafx.collections.ObservableMapWrapper.remove(ObservableMapWrapper.java:185)
  at org.jabref@100.0.0/org.jabref.model.entry.BibEntry.clearField(BibEntry.java:609)
  at org.jabref@100.0.0/org.jabref.model.entry.BibEntry.clearField(BibEntry.java:590)
  at org.jabref@100.0.0/org.jabref.logic.cleanup.ConvertToBibtexCleanup.lambda$cleanup$2(ConvertToBibtexCleanup.java:35)
  at java.base/java.util.Optional.ifPresent(Optional.java:176)
  at org.jabref@100.0.0/org.jabref.logic.cleanup.ConvertToBibtexCleanup.cleanup(ConvertToBibtexCleanup.java:25)
  at org.jabref@100.0.0/org.jabref.logic.importer.ImportCleanup.doPostCleanup(ImportCleanup.java:25)
  at org.jabref@100.0.0/org.jabref.logic.importer.ImportCleanup.lambda$doPostCleanup$0(ImportCleanup.java:36)
  at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
  at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
  at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
  at java.base/java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290)
  at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
  at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
  at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
  at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
  at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
  at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
@Siedlerchr
Copy link
Member

Siedlerchr commented Apr 4, 2021

Threading issue with the biblatex cleanup action which is run after import. It somehow triggers listener on ClearField in the UI which are not run on the FX thread

@Siedlerchr Siedlerchr added cleanup-ops bug Confirmed bugs or reports that are very likely to be bugs labels Apr 4, 2021
@sauliusg
Copy link
Contributor Author

sauliusg commented Apr 4, 2021

Update: the exception is triggered stably only when searching ArXiv, both with and without file download.

Search other bibliography repositories (Medline, Crossref, DBLP, CiteSeerX) mostly goes without an exception.

@Siedlerchr
Copy link
Member

I think I found the root cause:
The CompositeSearchBasedFetcher performs the ImportCleanup Operation, doPostCleanup which calls the coConvertToBibtexCleanup cleanup action which in turns calls entry.ClearField() and this triggers UI Bindings.

The key problem is that peformSearch is itself executed in a Background Thread.
The importCleanup has to be executed after the fetching in the onSucceeded. On a quick look, I think it must be placed in the ImportEntriesDialogViewModel as the BackgroundTasl from the WebSearchPane is passed to that class where finally the on Succeeded is called

public List<BibEntry> performSearch(QueryNode luceneQuery) throws FetcherException {
ImportCleanup cleanup = new ImportCleanup(BibDatabaseMode.BIBTEX);
// All entries have to be converted into one format, this is necessary for the format conversion
return fetchers.parallelStream()
.flatMap(searchBasedFetcher -> {
try {
return searchBasedFetcher.performSearch(luceneQuery).stream();
} catch (FetcherException e) {
LOGGER.warn(String.format("%s API request failed", searchBasedFetcher.getName()), e);
return Stream.empty();
}
})
.limit(maximumNumberOfReturnedResults)
.map(cleanup::doPostCleanup)
.collect(Collectors.toList());

@Siedlerchr Siedlerchr added the good first issue An issue intended for project-newcomers. Varies in difficulty. label Apr 4, 2021
@Noname690
Copy link
Contributor

Hi, I think this problem is interesting, could I try to fix it?

Siedlerchr added a commit that referenced this issue Apr 26, 2021
Siedlerchr added a commit that referenced this issue Apr 27, 2021
* Fix threading cleanup in performSearch

Fixes #7606

* Fix variable

* use bibdatabase mode

* cleanup is already done in import handler

* Should fix 1018
Siedlerchr added a commit that referenced this issue Apr 28, 2021
@koppor koppor moved this to Done in Prioritization Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs or reports that are very likely to be bugs cleanup-ops fetcher good first issue An issue intended for project-newcomers. Varies in difficulty.
Projects
Archived in project
3 participants