Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Java system properties always non-null?

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?

like image 957
miku Avatar asked Jun 10 '13 12:06

miku


People also ask

What is Java system properties?

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.

What are system properties?

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.

Where are system properties stored in Java?

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 .


1 Answers

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.

like image 145
Harald K Avatar answered Sep 22 '22 02:09

Harald K