From c0510da8dc33c7d2cda5e2dcd0761957f483f7a6 Mon Sep 17 00:00:00 2001 From: Tom Martin Date: Sun, 20 Oct 2024 15:30:43 +1100 Subject: [PATCH] Caught an error when accessing an invalid path. fixes #10548 --- CHANGELOG.md | 1 + .../importer/actions/OpenDatabaseAction.java | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffecf1b4298..af87c686037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -162,6 +162,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where DatabaseChangeDetailsView was not scrollable when reviewing external metadata changes [#11220](https://github.com/JabRef/jabref/issues/11220) - We fixed undo/redo for text fields. [#11420](https://github.com/JabRef/jabref/issues/11420) - We fixed an issue where clicking on a page number in the search results tab opens a wrong file in the document viewer. [#11432](https://github.com/JabRef/jabref/pull/11432) +- We fixed an issue where trying to open a library from a failed mounted directory on Mac would cause an error. [#10458](https://github.com/JabRef/jabref/issues/10548) ### Removed diff --git a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java index 605e389e76a..25cad7bc8d4 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -34,6 +34,7 @@ import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; import org.jabref.logic.shared.exception.NotASharedDatabaseException; import org.jabref.logic.util.BackgroundTask; +import org.jabref.logic.util.Directories; import org.jabref.logic.util.StandardFileType; import org.jabref.logic.util.TaskExecutor; import org.jabref.logic.util.io.FileHistory; @@ -102,11 +103,20 @@ public static void performPostOpenActions(ParserResult result, DialogService dia @Override public void execute() { - FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() + FileDialogConfiguration.Builder builder = new FileDialogConfiguration.Builder() .addExtensionFilter(StandardFileType.BIBTEX_DB) - .withDefaultExtension(StandardFileType.BIBTEX_DB) - .withInitialDirectory(getInitialDirectory()) - .build(); + .withDefaultExtension(StandardFileType.BIBTEX_DB); + + FileDialogConfiguration fileDialogConfiguration; + try { + fileDialogConfiguration = builder + .withInitialDirectory(getInitialDirectory()) + .build(); + } catch (IllegalArgumentException e) { // something went wrong with the directory, fallback to user directory + fileDialogConfiguration = builder + .withInitialDirectory(Directories.getUserDirectory()) + .build(); + } List filesToOpen = dialogService.showFileOpenDialogAndGetMultipleFiles(fileDialogConfiguration); openFiles(new ArrayList<>(filesToOpen));