I am using Eclipse with the PMD Plug-in (4.0.0.v20130510-1000) and got a lots of those violations and solved most of them, but i don't understand why DD anomaly occurs into below code
private boolean createFile(final String szFileName){
final File oFile = FileUtils.getFile(szFileName);
boolean bStatus;
try {
FileUtils.touch(oFile);
bStatus = true; // DD anomaly
} catch (IOException e) {
log.error("Failed to create new file. "+ e);
bStatus = false;
}
return bStatus;
}
I can't use multiple return statements, because multiple exit point rule gets break.
Tried another way, but getting DD anomaly to another line,
private boolean createFile(final String szFileName){
final File oFile = FileUtils.getFile(szFileName);
boolean bStatus = true; // DD anomaly
try {
FileUtils.touch(oFile);
} catch (IOException e) {
log.error("Failed to create new file. "+ e);
bStatus = false;
}
return bStatus;
}
An alternative approach is to have createFile throw an IOException and handle it upstream. Then you could have createFile return void, or better yet have it return the file it created. That will get rid of the DD anomaly you are receiving.
Alternative createFile:
private File createFile(final String szFileName) throws IOException {
final File oFile = FileUtils.getFile(szFileName);
FileUtils.touch(oFile);
return oFile;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With