consider the following code:
final Object x;
if(someCondition)
{
x = null;
}
else
{
x = new Object();
}
The above code does not match the intent of the rule
(at least what I think the intent is) of overwriting a
value with null.
Also consider:
Object x;
x = null;
for(...)
{
if(someCondition)
{
x = something;
break;
}
}
Some people (ok me) don't like to write Object x = null.
I think the rule should be augmented to be something like:
Assigning null to an object is fine if there have been
no prior assignments.
Thanks,
..darcy
Logged In: YES
user_id=554117
Looks like 3.5 fixes the first case above but not the second
case... my number of PMD warnings just went down :-)
Logged In: YES
user_id=5159
Originator: NO
Yup, we no longer flag this if it's an assignment to a final variable. I've put a note in that rule about this second case...
Yours,
tom
http://pmdapplied.com/