Showing posts with label How to remove java system property. Show all posts
Showing posts with label How to remove java system property. Show all posts

Tuesday, 21 January 2014

Removing system property

Hi guys its being awhile I guess its because of so much i most be involved in well but this was short and prompting. Recently i was faced with removing a key from System.properties(), what i found out is that some developer, might try to approach this by setting the value to null, but then 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.


  2. System.getProperties().remove("key");
    

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 System.getProperties()