Personal tools

Jun 26, 2010

System.getProperty() returns null

Filed Under:

How to avoid a null pointer using System.getProperty() within a java agent.

Sometimes, for some reason, you have to do it. I'm talking about the use of System.setProperty() method within a java agent. If you don't pay attention it's easy to get a null pointer as result. Infact I got it. 

After a quick search I found out a way to solve the issue:

I will use "jna.library.path" as example.

First of all add the following line in "java.policy" file (in the "jvm\lib\security" folder below the Domino program folder).

permission java.util.PropertyPermission "jna.library.path", "read,write";


After that, add the java code to your agent :

String jnaProperty = "jna.library.path";
if(System.getProperty(jnaProperty) == null) {
   System.setProperty(jnaProperty,"your path");
And that it's all.