Questions tagged [pmd]

PMD scans source code and looks for potential problems like possible bugs, dead code, suboptimal code, overcomplicated expressions, and duplicate code. PMD supports Java, JavaScript, XML, and many more.

PMD scans source code and looks for potential problems like possible bugs, dead code, suboptimal code, overcomplicated expressions, and .

857 questions
143
votes
4 answers

RegExp matching string not starting with my

For PMD I'd like to have a rule which warns me of those ugly variables which start with my. This means I have to accept all variables which do NOT start with my. So, I need a RegEx (re) which behaves as follows: re.match('myVar') ==…
Dominik Sandjaja
  • 6,326
  • 6
  • 52
  • 77
126
votes
8 answers

Is SonarQube Replacement for Checkstyle, PMD, FindBugs?

We are working on a web project from scratch and are looking at the following static code analysis tools. Conventions (Checkstyle) Bad practices (PMD) Potential bugs (FindBugs) The project is built on Maven. Instead of using multiple tools for…
Johnny
  • 1,317
  • 2
  • 10
  • 6
113
votes
3 answers

What are the differences between PMD and FindBugs?

There was a question comparing PMD and CheckStyle. However, I can't find a nice breakdown on the differences/similarities between PMD and FindBugs. I believe a key difference is that PMD works on source code, while FindBugs works on compiled…
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
113
votes
7 answers

Avoid printStackTrace(); use a logger call instead

In my application, I am running my code through PMD.It shows me this message: Avoid printStackTrace(); use a logger call instead. What does that mean?
user1305398
  • 3,550
  • 5
  • 26
  • 42
94
votes
17 answers

Checkstyle vs. PMD

We are introducing static analysis tools into the build system for our Java product. We are using Maven2 so Checkstyle and PMD integration come for free. However it looks like there is a large overlap in functionality between these two tools, in…
John Stauffer
  • 16,150
  • 10
  • 40
  • 35
71
votes
4 answers

Unable to locate Source XRef to link to

I have a big Maven project that uses the PMD plugin for code quality checks. since I started using the PMD plugin i get the following warning message: [WARNING] Unable to locate Source XRef to link to - DISABLED I googled and found that i need to…
ufk
  • 30,912
  • 70
  • 235
  • 386
55
votes
6 answers

Logger vs. System.out.println

I'm using the PMD plugin for eclipse and it gives me an error when using System.out.println() with the explanation: System.(out|err).print is used, consider using a logger. My question is - What is a Logger? How is it used to print to the screen?…
Amir Rachum
  • 76,817
  • 74
  • 166
  • 248
54
votes
1 answer

Unsupported @SuppressWarnings("PMD.DoNotCallSystemExit")

I need to use System.exit(0) in an application. Eclipse has the PMD plugin installed and complains about this line of code. Adding @SuppressWarnings ("PMD.DoNotCallSystemExit") remove that warning but now I get a warning that this SuppressWarnings…
user342495
  • 1,453
  • 1
  • 11
  • 10
46
votes
8 answers

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

We have a Java Application that has a few modules that know to read text files. They do it quite simply with a code like this: BufferedReader br = new BufferedReader(new FileReader(file)); String line = null; while ((line = br.readLine()) !=…
RonK
  • 9,472
  • 8
  • 51
  • 87
36
votes
5 answers

Java PMD warning on non-transient class member

On line: private boolean someFlag; I get the following PMD warning: Found non-transient, non-static member. Please mark as transient or provide accessors. Can someone please explain why this warning is there and what it means? (I understand how…
Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
36
votes
6 answers

What is the reason for these PMD rules?

DataflowAnomalyAnalysis: Found 'DD'-anomaly for variable 'variable' (lines 'n1'-'n2'). DataflowAnomalyAnalysis: Found 'DU'-anomaly for variable 'variable' (lines 'n1'-'n2'). DD and DU sound familiar...I want to say in things like testing…
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
30
votes
4 answers

The "Why" behind PMD's rules

Is there a good resource which describes the "why" behind PMD rule sets? PMD's site has the "what" - what each rule does - but it doesn't describe why PMD has that rule and why ignoring that rule can get you in trouble in the real world. In…
James Kingsbery
  • 7,298
  • 2
  • 38
  • 67
30
votes
4 answers

Efficiency: switch statements over if statements

PMD tells me A switch with less than 3 branches is inefficient, use a if statement instead. Why is that? Why 3? How do they define efficiency?
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
29
votes
4 answers

How to export FindBugs/PMD/Checkstyle rules from Sonar and import into Netbeans

My company has sonar set up to with various plugins (PMD, FindBugs, CheckStyle), and although it is very useful as is (it runs after every Jenkins build that was triggered by a check-in to SVN), I would like it if I could run these various plugins…
jalsk
  • 293
  • 1
  • 3
  • 6
28
votes
2 answers

PMD ruleset file

I am trying to figure where is the default ruleset file, name of the default ruleset file and how do we add our own rules to it. I tried to google, but that is just confusing me. So far, I have put the pmd plugin inside eclipse plugins folder and in…
Nisha
  • 289
  • 1
  • 5
  • 6
1
2 3
57 58