Преглед на файлове

Fixed violation of method contract

See: https://github.com/cryptomator/cryptomator/pull/1307#discussion_r472857043
JaniruTEC преди 4 години
родител
ревизия
d5b8996a39
променени са 1 файла, в които са добавени 6 реда и са изтрити 4 реда
  1. 6 4
      main/commons/src/main/java/org/cryptomator/common/mountpoint/TemporaryMountPointChooser.java

+ 6 - 4
main/commons/src/main/java/org/cryptomator/common/mountpoint/TemporaryMountPointChooser.java

@@ -41,17 +41,19 @@ public class TemporaryMountPointChooser implements MountPointChooser {
 
 	@Override
 	public Optional<Path> chooseMountPoint() {
-		//Shouldn't throw, but let's keep #orElseThrow in case we made a mistake and the check in #isApplicable failed
-		Path parent = this.environment.getMountPointsDir().orElseThrow();
+		return this.environment.getMountPointsDir().map(this::choose);
+	}
+
+	private Path choose(Path parent) {
 		String basename = this.vaultSettings.mountName().get();
 		for (int i = 0; i < MAX_TMPMOUNTPOINT_CREATION_RETRIES; i++) {
 			Path mountPoint = parent.resolve(basename + "_" + i);
 			if (Files.notExists(mountPoint)) {
-				return Optional.of(mountPoint);
+				return mountPoint;
 			}
 		}
 		LOG.error("Failed to find feasible mountpoint at {}{}{}_x. Giving up after {} attempts.", parent, File.separator, basename, MAX_TMPMOUNTPOINT_CREATION_RETRIES);
-		return Optional.empty();
+		return null;
 	}
 
 	@Override