瀏覽代碼

now passing unchecked CryptoExceptions up through various closures, thus being able to catch “InvalidPassphraseException” in UI

Sebastian Stenzel 8 年之前
父節點
當前提交
2687c02e31

+ 4 - 2
main/commons/src/main/java/org/cryptomator/common/LazyInitializer.java

@@ -50,12 +50,14 @@ public final class LazyInitializer {
 		}
 	}
 
-	private static <T> UnaryOperator<T> invokeFactoryIfNull(SupplierThrowingException<T, ?> factory) throws InitializationException {
+	private static <T, E extends Exception> UnaryOperator<T> invokeFactoryIfNull(SupplierThrowingException<T, E> factory) throws InitializationException {
 		return currentValue -> {
 			if (currentValue == null) {
 				try {
 					return factory.get();
-				} catch (Throwable e) {
+				} catch (RuntimeException e) {
+					throw e; // don't catch unchecked exceptions
+				} catch (Exception e) {
 					throw new InitializationException(e);
 				}
 			} else {

+ 1 - 1
main/pom.xml

@@ -28,7 +28,7 @@
 
 		<!-- dependency versions -->
 		<cryptomator.cryptolib.version>1.0.9</cryptomator.cryptolib.version>
-		<cryptomator.cryptofs.version>1.0.1</cryptomator.cryptofs.version>
+		<cryptomator.cryptofs.version>1.1.0-SNAPSHOT</cryptomator.cryptofs.version>
 		<cryptomator.webdav.version>0.3.0-SNAPSHOT</cryptomator.webdav.version>
 		<cryptomator.jni.version>1.0.0</cryptomator.jni.version>
 		<log4j.version>2.1</log4j.version>

+ 2 - 1
main/ui/src/main/java/org/cryptomator/ui/model/Vault.java

@@ -26,6 +26,7 @@ import org.cryptomator.common.LazyInitializer;
 import org.cryptomator.cryptofs.CryptoFileSystem;
 import org.cryptomator.cryptofs.CryptoFileSystemProperties;
 import org.cryptomator.cryptofs.CryptoFileSystemProvider;
+import org.cryptomator.cryptolib.api.CryptoException;
 import org.cryptomator.cryptolib.api.InvalidPassphraseException;
 import org.cryptomator.frontend.webdav.WebDavServer;
 import org.cryptomator.frontend.webdav.mount.Mounter.CommandFailedException;
@@ -76,7 +77,7 @@ public class Vault {
 		return LazyInitializer.initializeLazily(cryptoFileSystem, () -> createCryptoFileSystem(passphrase), IOException.class);
 	}
 
-	private CryptoFileSystem createCryptoFileSystem(CharSequence passphrase) throws IOException {
+	private CryptoFileSystem createCryptoFileSystem(CharSequence passphrase) throws IOException, CryptoException {
 		CryptoFileSystemProperties fsProps = CryptoFileSystemProperties.cryptoFileSystemProperties().withPassphrase(passphrase).build();
 		CryptoFileSystem fs = CryptoFileSystemProvider.newFileSystem(getPath(), fsProps);
 		closer.closeLater(fs);