null
, but it turns out that System.setProperty(key, val)
will throw NullPointerException when either key or value is null. Here are 2 ways to remove or clear a system property:1.
clearProperty(String key)
introduced in JDK 1.5.System.clearProperty("key");2.
Properties sysProps = System.getProperties();When java security manager is enabled, Both methods need specific permissions to succeed. Approach 1 requires
sysProps.remove("key");
PropertyPermission "key", "read,write"
. Approach 2 requires a much wider permission: PropertyPermission "*", "read,write"
, because you are free to modify/remove all system properties with the returned object from System.getProperties()
Tags: