Open
Description
Compiler version
3.2.1
Minimized code
object SyspropTest {
def main(args: Array[String]) : Unit = {
val n = "a.b"
val v = System.getProperty(n)
println(s"${n}=${v}")
val argStr = args.mkString(", ")
println(s"Command-line arguments: ${argStr}")
}
}
Output
If first compiled with scalac, then executed as scala -Da.b=c SyspropTest 1 2 3
:
a.b=null
Command-line arguments: -Da.b=c, 1, 2, 3
Expectation
a.b=c
Command-line arguments: 1, 2, 3
Notes
- The output above is the result of first calling scalac followed by scala. However if the source file is sent directly to scala (instead of being compiled first) result differs in that the
-Dname=prop
option is silently dropped, while still not setting the property. That is,scala -Da.b=c sysprop.scala 1 2 3
(assuming that the example code above resides in filesysprop.scala
) yields:
a.b=null
Command-line arguments: 1, 2, 3
Note that while the option is not part of args
in this case, the property remains null.
- It is possible to work around the issue by employing the
-J
command line option.scala -J-Da.b=c SyspropTest 1 2 3
gives the expected result (as-J
is stripped and-Da.b=c
passed to java)
a.b=c
Command-line arguments: 1, 2, 3
If needed - java -version
:
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu220.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu220.04, mixed mode, sharing)