javasystem-properties

Set System property to Null in Java


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?


Solution

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

    System.clearProperty("workingDir");