Set System propery to Null in Java

Victoria Seniuk picture Victoria Seniuk · Dec 1, 2010 · Viewed 12.1k times · Source

In my unit tests I need to set the "workingDir" system property to Null.

But I can not do somesing like this, because It give me NullPointerException:

System.setProperty("workingDir", null);

How can I do it?

Answer

Jon Skeet picture Jon Skeet · Dec 1, 2010

You can't set a property to have an actual null value - you can only clear it, like this:

System.clearProperty("workingDir");