In an attempt to begin coding with some sort of consistant structure I looked at PMD which basically checks any code and offers hints based on a ruleset.
Consider the following code...
I need to check for the existance of "MyEnvVar" which is an environment variable and put whatever is in that environment variable in the String variable - sMyEnvVar. If the var is not set I will throw an exception etc.
The code works, however PMD complains about "Possible unsafe assignment to a non-final static field in a constructor." I am not concerned about PMD being any sort of holy grail to fix all my coding faults but it is a starting point.
1) What does the 'unsafe assignment' message mean? 2) How can the above code be written more correctly?
Of all the things I've lost in my life it's my mind I miss the most.
This code updates a class variable every time an instance of that class is created. That sounds a little shakey but let's assume that's actually what you want. In that case synchronize access to sMyEnvVar.
BTW, what's the 's' prefix for on sMyEnvVar? [ October 01, 2005: Message edited by: Rick O'Shay ]
Joined: Jan 29, 2003
Excellent. Add to my list: the compiler complains because it's unsafe ... make it safe!