How to avoid DD - anomaly ?
Hello!I try to have time to use some code-inspecting program like PMD before I deliver the code.
Sometimes I get this warnings or "i":s from PMD saying:
Multiple markers at this line
- Found 'DD'-anomaly for variable 'retValue' (lines '28'-'36').
- Found 'DD'-anomaly for variable 'retValue' (lines '28'-'32').
27 public boolean accept(final File file) {
28 boolean retValue = false;
29
30 if (file.isDirectory() )
31 {
32 retValue = true;
33 }
34 else if( checkTheFile(file) )
34 {
36 retValue = true;
37 }
return retValue;
}
...but I'm not sure what they mean?
In the example above I have also tried like:
public boolean accept(final File file) {
boolean retValue = false;
if (file.isDirectory() ||(readConfigurationAssembly(file)) )
{
retValue = true;
}
return retValue;
}
But then I get:
Found 'DD'-anomaly for variable 'retValue' (lines '28'-'32').
I found this explanation but I do not sure I understand it, acctually I do not understand it at all:
DD - Anomaly: A recently defined variable is redefined. This is ominous but don't have to be a bug.
...at:
http://pmd.sourceforge.net/rules/controversial.html
Is there a better way to write this code?
Btw PMD doesn't like diffrent return points either.
Love to get some comments about how to make PMD happy.
Best regards
Fredrik