From b50fff3d49e5d768d411af3ff48e2b0a522e3f4a Mon Sep 17 00:00:00 2001 From: ShellWen Date: Fri, 9 Aug 2024 22:24:12 +0800 Subject: [PATCH] Add Android-specific exception message --- .../apache/sshd/common/util/io/PathUtils.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/io/PathUtils.java b/sshd-common/src/main/java/org/apache/sshd/common/util/io/PathUtils.java index 8b2da5c0d..88023598d 100644 --- a/sshd-common/src/main/java/org/apache/sshd/common/util/io/PathUtils.java +++ b/sshd-common/src/main/java/org/apache/sshd/common/util/io/PathUtils.java @@ -28,6 +28,7 @@ import java.util.function.Supplier; import org.apache.sshd.common.util.GenericUtils; +import org.apache.sshd.common.util.OsUtils; import org.apache.sshd.common.util.ValidateUtils; import org.apache.sshd.common.util.functors.UnaryEquator; @@ -53,10 +54,19 @@ public final class PathUtils { private static final AtomicReference> USER_HOME_RESOLVER_HOLDER = new AtomicReference<>(); private static final class LazyDefaultUserHomeFolderHolder { - private static final Path PATH - = Paths.get(ValidateUtils.checkNotNullAndNotEmpty(System.getProperty("user.home"), "No user home")) - .toAbsolutePath() - .normalize(); + private static final Path PATH; + + static { + String exceptionMessage = OsUtils.isAndroid() + ? "No user home folder available. You should call " + + "org.apache.sshd.common.util.io.PathUtils.setUserHomeFolderResolver() " + + "method to set user home folder as there is no home folder on Android" + : "No user home folder available"; + PATH = Paths + .get(ValidateUtils.checkNotNullAndNotEmpty(System.getProperty("user.home"), exceptionMessage)) + .toAbsolutePath() + .normalize(); + } private LazyDefaultUserHomeFolderHolder() { throw new UnsupportedOperationException("No instance allowed");