From 70f6a4877cace7221817b1f44983ed6c82321a5e Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Mon, 25 Jan 2021 21:38:46 +0100 Subject: [PATCH] Make sure not to catch Errors --- .../cryptomator/ui/unlock/UnlockWorkflow.java | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java index 8cb7e0752..e91c5533c 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java @@ -165,15 +165,7 @@ public class UnlockWorkflow extends Task { assert requirement != MountPointRequirement.PARENT_OPT_MOUNT_POINT; //Not implemented anywhere (yet) Throwable cause = impExc.getCause(); - //Cause is either null (cause the IMPE was thrown directly, e.g. because no MPC succeeded) - //or the cause was not an Exception (but some other kind of Throwable) - //Either way: Handle as generic error - if (!(cause instanceof Exception)) { - handleGenericError(impExc); - return; - } - - //From here on handle the cause, not the caught exception + // TODO: apply https://openjdk.java.net/jeps/8213076 in future JDK versions if (cause instanceof NotDirectoryException) { if (requirement == MountPointRequirement.PARENT_NO_MOUNT_POINT) { LOG.error("Unlock failed. Parent folder is missing: {}", cause.getMessage()); @@ -182,23 +174,17 @@ public class UnlockWorkflow extends Task { } showInvalidMountPointScene(); return; - } - - if (cause instanceof FileAlreadyExistsException) { + } else if (cause instanceof FileAlreadyExistsException) { LOG.error("Unlock failed. Mountpoint already exists: {}", cause.getMessage()); showInvalidMountPointScene(); return; - } - - if (cause instanceof DirectoryNotEmptyException) { + } else if (cause instanceof DirectoryNotEmptyException) { LOG.error("Unlock failed. Mountpoint not an empty directory: {}", cause.getMessage()); showInvalidMountPointScene(); return; + } else { + handleGenericError(impExc); } - - //Everything else (especially IOException) results in a generic error - //This must be done after the other exceptions because they extend IOException... - handleGenericError(cause); } private void showInvalidMountPointScene() {