Skip to content

Commit

Permalink
Fix crash when HOME env variable is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgab committed Mar 6, 2020
1 parent 26009f9 commit c60cba9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion javalib/src/main/scala/java/lang/System.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ object System {
sysProps.setProperty("user.language", userLang)
sysProps.setProperty("user.country", userCountry)
}
sysProps.setProperty("user.home", getenv("HOME"))
val home = getenv("HOME")
if (home != null) sysProps.setProperty("user.home", home)
val buf = stackalloc[scala.Byte](1024)
unistd.getcwd(buf, 1024) match {
case null =>
Expand Down
2 changes: 1 addition & 1 deletion unit-tests/src/test/scala/java/lang/SystemSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ object SystemSuite extends tests.Suite {
assert(delta <= tolerance)
}

test("Property user.home should be set") {
test("Property user.home should be set if env variable is set") {
assertEquals(System.getProperty("user.home"), System.getenv("HOME"))
}

Expand Down

1 comment on commit c60cba9

@ekrich
Copy link
Member

@ekrich ekrich commented on c60cba9 Mar 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the behavior if it is on the JVM? Haven't checked but maybe user.home is an empty string?

Please sign in to comment.