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
14
votes
2 answers

Remove a single rule check from PMD in maven plugin

I want to exclude a single PMD rule in POM, but it is not working. I have tried creating a pmd-exclude.xml (in the same dir as the pom.xml): Remove rules
Fernando M. Pinheiro
  • 610
  • 1
  • 10
  • 21
12
votes
6 answers

Does the method name length have any impact whatsoever on the performance?

I am a senior developer, so this appears to me a stupid question. My answer should be NO, or WHAT? NO!!! But I was in a meeting yesterday, and I was explaining some PMD results. When we get to the "too long method name" issue, I started to explain…
ERNESTO ARROYO RON
  • 992
  • 1
  • 9
  • 22
12
votes
2 answers

PMD rule God Class - understanding the metrics

We are using the source code analyzer PMD in our Java project. I am trying to resolve the reported issues and I am currently struggling with the GodClass rule. I know that the idea is not to create huge classes. However, I don't like the word…
Cimlman
  • 3,404
  • 5
  • 25
  • 35
12
votes
1 answer

Are inner classes in enums always static in Java?

I have an enum class which contains an inner class in Java. For example (In the real code, there are some methods declared on the enum that internally use the inner class): public enum MyEnum{ VALUE_1, VALUE_2; private static class…
Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
12
votes
3 answers

PMD Overridable method called during object construction

I have the following structure public class parent { int value ; } public class child extends parent { int childValue; public child(){} public child (int value){ this.childValue = value ; // this line cause…
User
  • 573
  • 3
  • 15
  • 28
12
votes
5 answers

Can you exclude a source file for a specific PMD rule?

When defining a PMD ruleset is it possible to exclude a source file from a specific rule? I want to do something like the following: Exclude only seems to be…
Mark
  • 28,783
  • 8
  • 63
  • 92
11
votes
1 answer

Not able to exclude some rules from PMD

I'm just trying to add PMD to my Spring Boot project but I'm facing some issues trying to exclude some rules from category/java/errorprone.xml ruleset. I'm using the gradle plugin as follows: pmd { ruleSetConfig =…
Victor Escobar
  • 514
  • 1
  • 6
  • 15
11
votes
4 answers

Add an empty string vs toString - why is it bad?

According to the tool PMD, the following is a bad practice: String s = "" + 123; // bad String t = Integer.toString(456); // ok This is an inefficient way to convert any type to a `String`. Why is it a bad thing to do?
corgrath
  • 11,673
  • 15
  • 68
  • 99
11
votes
5 answers

What is the right position of literals in String Comparison?

I have if (localName.equals("TaxName")) { but PMD says Position literals first in String comparisons
unj2
  • 52,135
  • 87
  • 247
  • 375
11
votes
2 answers

Code quality rule for finding non threadsafe singleton spring implementations

Is there any Checkstyle, PMD or Findbugs rule which could find the following non threadsafe spring singleton implementation? private String helperVar; public String getValue(String value) { helperVar = value; return convertValue(); } private…
B4dT0bi
  • 623
  • 4
  • 21
11
votes
3 answers

How to ignore "id" in Short Variable rule using PMD

I am using PMD plugin (version 4.0.2) for Eclipse (Eclipse Kepler Java EE). I have configured a naming rule: ShortVariable. This works fine except for parameters like "id" and "e". I want PMD to ignore these. So I searched for a way to ignore…
SanderDN
  • 496
  • 6
  • 19
11
votes
4 answers

Gradle's PMD plugin: what are acceptable arguments?

Java 1.7.0_40 Gradle 1.10 I've never used Gradle's PMD plugin and I'm running into trouble trying to add rule sets to my build.gradle. The Pmd documentation is not clear about what the valid values of ruleSets are. Their example is ruleSets =…
kuporific
  • 10,053
  • 3
  • 42
  • 46
11
votes
1 answer

Make Maven PMD Plugin Print Errors to Console

How can I make the Maven PMD Plugin print the PMD errors that it finds to the console during a "mvn install"? Right now, the output is going into a pmd error file in the target dir. It looks like old version of the plugin supported the variable…
HappyCoder86
  • 2,267
  • 3
  • 25
  • 40
11
votes
6 answers

Can't import PMD Ruleset in Eclipse

I would like to use the same Ruleset in my IDE (Eclipse) that my Sonar profile. I got the PMD XML ruleset from the Sonar Permalinks and would like to import it into my PMD Eclipse Plugin but when i try to do it, the "OK" button is desactivated…
Lionel Père
  • 526
  • 2
  • 5
  • 17
10
votes
4 answers

Why does the main Spring Boot application always trigger PMD's HideUtilityClassConstructorCheck?

The standard Spring Boot application has some main method class file, say SampleApplication.java, that looks like this: @SpringBootApplication @RestController public class SampleApplication { public static void main(final String[] args) { …
rocketscientist
  • 2,428
  • 3
  • 19
  • 18
1 2
3
57 58