I thought I could remove a system property by setting its value to
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:
clearProperty(String key) introduced in JDK 1.5.
Properties sysProps = System.getProperties();When java security manager is enabled, Both methods need specific permissions to succeed. Approach 1 requires
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