Skip to content

Commit fa40fd3

Browse files
committed
Replace Collections.emptyList() with List.of() and improve exception handling
1 parent fd53d23 commit fa40fd3

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/main/java/org/jabref/gui/externalfiles/ImportHandler.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.jabref.logic.util.BackgroundTask;
4545
import org.jabref.logic.util.StandardFileType;
4646
import org.jabref.logic.util.TaskExecutor;
47+
import org.jabref.logic.util.URLUtil;
4748
import org.jabref.logic.util.UpdateField;
4849
import org.jabref.logic.util.io.FileUtil;
4950
import org.jabref.model.FieldChange;
@@ -374,7 +375,7 @@ public List<BibEntry> handleBibTeXData(String entries) {
374375
return result;
375376
} catch (ParseException ex) {
376377
LOGGER.error("Could not paste", ex);
377-
return Collections.emptyList();
378+
return List.of();
378379
}
379380
}
380381

@@ -400,16 +401,16 @@ public void importStringConstantsWithDuplicateCheck(Collection<BibtexString> str
400401

401402
public List<BibEntry> handleStringData(String data) throws FetcherException {
402403
if ((data == null) || data.isEmpty()) {
403-
return Collections.emptyList();
404+
return List.of();
404405
}
405406
LOGGER.debug("Checking if URL is a PDF: {}", data);
406407

407-
if (org.jabref.logic.util.URLUtil.isURL(data) && data.toLowerCase().endsWith(".pdf")) {
408+
if (URLUtil.isURL(data) && data.toLowerCase().endsWith(".pdf")) {
408409
try {
409410
return handlePdfUrl(data);
410411
} catch (IOException ex) {
411412
LOGGER.error("Could not handle PDF URL", ex);
412-
return Collections.emptyList();
413+
return List.of();
413414
}
414415
}
415416

@@ -434,7 +435,7 @@ private List<BibEntry> tryImportFormats(String data) {
434435
return unknownFormatImport.parserResult().getDatabase().getEntries();
435436
} catch (ImportException ex) { // ex is already localized
436437
dialogService.showErrorDialogAndWait(Localization.lang("Import error"), ex);
437-
return Collections.emptyList();
438+
return List.of();
438439
}
439440
}
440441

@@ -462,7 +463,7 @@ private List<BibEntry> handlePdfUrl(String pdfUrl) throws IOException {
462463
Optional<Path> targetDirectory = bibDatabaseContext.getFirstExistingFileDir(preferences.getFilePreferences());
463464
if (targetDirectory.isEmpty()) {
464465
LOGGER.warn("File directory not available while downloading {}.", pdfUrl);
465-
return Collections.emptyList();
466+
return List.of();
466467
}
467468
URLDownload urlDownload = new URLDownload(pdfUrl);
468469
String filename = deriveFileNameFromUrl(pdfUrl);
@@ -471,7 +472,7 @@ private List<BibEntry> handlePdfUrl(String pdfUrl) throws IOException {
471472
urlDownload.toFile(targetFile);
472473
} catch (FetcherException fe) {
473474
LOGGER.error("Error downloading PDF from URL", fe);
474-
throw new IOException("Error downloading PDF", fe);
475+
return List.of();
475476
}
476477
try {
477478
PdfMergeMetadataImporter importer = new PdfMergeMetadataImporter(preferences.getImportFormatPreferences());
@@ -492,9 +493,9 @@ private List<BibEntry> handlePdfUrl(String pdfUrl) throws IOException {
492493
entries.add(emptyEntry);
493494
}
494495
return entries;
495-
} catch (Exception ex) {
496-
LOGGER.error("Error importing PDF from URL", ex);
497-
return Collections.emptyList();
496+
} catch (IOException ex) {
497+
LOGGER.error("Error importing PDF from URL - IO issue", ex);
498+
return List.of();
498499
}
499500
}
500501

0 commit comments

Comments
 (0)