Skip to content

Commit

Permalink
Merge pull request #580 from ShellWen/fix/android-user-home
Browse files Browse the repository at this point in the history
Add Android-specific exception message when finding user home
  • Loading branch information
tomaswolf authored Aug 22, 2024
2 parents 8408a70 + b50fff3 commit 40a08a4
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -53,10 +54,19 @@ public final class PathUtils {
private static final AtomicReference<Supplier<? extends Path>> 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");
Expand Down

0 comments on commit 40a08a4

Please sign in to comment.