There are a couple of Java system properties, among them things like java.home
and path.separator
, user.home
. The spec does not mention any formal promises on the existence of those values.
Especially I am interested in user.home
. Does it always point to some existing path?
Java™ system properties determine the environment in which a Java program runs by starting a Java virtual machine with a set of values. You can choose to use the default values for Java system properties or you can specify values for them by adding parameters to the command line when you start your application.
System Properties is a section of Microsoft Windows for editing operating system settings, including hardware settings, connectivity, user profiles, security settings, and the computer name.
The system properties are actually stored in a PropertiesPropertySource which by default delegates to System. getProperties() as the source . That happens to be a synchronized Hashtable which implements Map .
I think you can safely assume that all the properties in that list is always available in any recent (Oracle-provided) JVM.
However, a null
check is more defensive, and not expensive in this case.
I've never seen user.home
to be null or be incorrectly specified by default. However, keep in mind that users can override with -Duser.home=...
, so you can't rely on it to point to an existing path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With