What is the reason for these PMD rules?

DD and DU anomalies (if I remember correctly—I use FindBugs and the messages are a little different) refer to assigning a value to a local variable that is never read, usually because it is reassigned another value before ever being read. A typical case would be initializing some variable with null when it is declared. … Read more

Iterating over the content of a text file line by line – is there a best practice? (vs. PMD’s AssignmentInOperand)

I know is an old post but I just had the same need (almost) and I solve it using a LineIterator from FileUtils in Apache Commons. From their javadoc: LineIterator it = FileUtils.lineIterator(file, “UTF-8”); try { while (it.hasNext()) { String line = it.nextLine(); // do something with line } } finally { it.close(); } Check … Read more

Logger vs. System.out.println

See this short introduction to log4j. The issue is in using System.out to print debugging or diagnostic information. It is a bad practice because you cannot easily change log levels, turn it off, customize it, etc. However if you are legitimately using System.out to print information to the user, then you can ignore this warning.

Unable to locate Source XRef to link to

You should add the maven-jxr-plugin to the reportingPlugin section. <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jxr-plugin</artifactId> <version>3.3.0</version> </plugin> </plugins> </reporting> Re run it and enjoy. BTW, maybe you’ll need to run once the jxr:jxr goal to first generate some file that will be used by pmd.

Checkstyle vs. PMD

You should definitely use FindBugs. In my experience, the false-positive rate is very low, and even the least-critical warnings it reports are worth addressing to some extent. As for Checkstyle vs. PMD, I would not use Checkstyle since it is pretty much only concerned with style. In my experience, Checkstyle will report on a ton … Read more

Avoid printStackTrace(); use a logger call instead

It means you should use logging framework like logback or log4j and instead of printing exceptions directly: e.printStackTrace(); you should log them using this frameworks’ API: log.error(“Ops!”, e); Logging frameworks give you a lot of flexibility, e.g. you can choose whether you want to log to console or file – or maybe skip some messages … Read more

What are the differences between PMD and FindBugs?

I’m using both. I think they complement each other. As you said, PMD works on source code and therefore finds problems like: violation of naming conventions, lack of curly braces, misplaced null check, long parameter list, unnecessary constructor, missing break in switch, etc. PMD also tells you about the Cyclomatic complexity of your code which … Read more