From d0a15b8a4a0873109e9c863fab7391e0ec331c26 Mon Sep 17 00:00:00 2001 From: ni-wi Date: Sat, 19 Mar 2022 18:42:11 +0100 Subject: [PATCH] fix import of unlinked files (#8444) --- CHANGELOG.md | 1 + .../jabref/gui/externalfiles/ImportHandler.java | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d9a8f8bb86..7311102db3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue when reading non-UTF-8 encoded. When no encoding header is present, the encoding is now detected from the file content (and the preference option is disregarded) [#8417](https://github.com/JabRef/jabref/issues/8417) - We fixed an issue where pasting a URL was replacing + signs by spaces making the URL unreachable. [#8448](https://github.com/JabRef/jabref/issues/8448) - We fixed an issue where creating subsidiary files from aux files created with some versions of biblatex would produce incorrect results. [#8513](https://github.com/JabRef/jabref/issues/8513) +- We fixed an issue where not all found unlinked local files were imported correctly due to some race condition. [#8444](https://github.com/JabRef/jabref/issues/8444) ### Removed diff --git a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java index 53c2f0398d7..0cb650d805f 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java @@ -68,18 +68,17 @@ public ExternalFilesEntryLinker getLinker() { return linker; } - public BackgroundTask> importFilesInBackground(List files) { + public BackgroundTask> importFilesInBackground(final List files) { return new BackgroundTask<>() { private int counter; - private List entriesToAdd; private final List results = new ArrayList<>(); @Override protected List call() { counter = 1; CompoundEdit ce = new CompoundEdit(); - for (Path file: files) { - entriesToAdd = Collections.emptyList(); + for (final Path file : files) { + final List entriesToAdd = new ArrayList<>(); if (isCanceled()) { break; @@ -87,7 +86,7 @@ protected List call() { DefaultTaskExecutor.runInJavaFXThread(() -> { updateMessage(Localization.lang("Processing file %0", file.getFileName())); - updateProgress(counter, files.size() - 1); + updateProgress(counter, files.size() - 1d); }); try { @@ -100,10 +99,10 @@ protected List call() { } if (!pdfEntriesInFile.isEmpty()) { - entriesToAdd = pdfEntriesInFile; + entriesToAdd.addAll(pdfEntriesInFile); addResultToList(file, true, Localization.lang("Importing using extracted PDF data")); } else { - entriesToAdd = Collections.singletonList(createEmptyEntryWithLink(file)); + entriesToAdd.add(createEmptyEntryWithLink(file)); addResultToList(file, false, Localization.lang("No metadata found. Creating empty entry with file link")); } } else if (FileUtil.isBibFile(file)) { @@ -112,10 +111,10 @@ protected List call() { addResultToList(file, false, bibtexParserResult.getErrorMessage()); } - entriesToAdd = bibtexParserResult.getDatabaseContext().getEntries(); + entriesToAdd.addAll(bibtexParserResult.getDatabaseContext().getEntries()); addResultToList(file, false, Localization.lang("Importing bib entry")); } else { - entriesToAdd = Collections.singletonList(createEmptyEntryWithLink(file)); + entriesToAdd.add(createEmptyEntryWithLink(file)); addResultToList(file, false, Localization.lang("No BibTeX data found. Creating empty entry with file link")); } } catch (IOException ex) {