Trace all calls to System.getProperty method

Many libraries use system properties for settings.  For example, you usually have to set a property to enable debug traces or to activate certain behaviors.  However, sometimes system properties that are used are not well documented or you are not sure that they are having some effect.  In such cases it would be useful to have a way to know which system properties are queried.

There are several manners to do this but I have found a simple way that is not so intrusive. By creating a custom Security Manager you can define a method that checks property accesses. This method is able to send to the logger or to the standard output what property has been queried.

public class PropertyAccessPrinterSecurityManager extends SecurityManager {
    @Override
    public void checkPropertyAccess(String key) {
        System.out.println("System.getProperty(\"+key+"\")");
    }
}

This class should be compiled and available in the classpath.
Now we create in the current directory a file named “java.policy” with the following content:

grant {
	permission java.security.AllPermission;
};

We just have everything we need to trace calls to System.getProperty. Next we add these parameters to the java call:

java -Djava.security.manager=PropertyAccessPrinterSecurityManager -Djava.security.policy==java.policy