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");