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
10
votes
1 answer

PMD "Bean Members Should Serialize" rule. Can we do it in more smart way?

Here is (probably good for someone) "Bean Members Should Serialize" PMD rule which states the following: If a class is a bean, or is referenced by a bean directly or indirectly it needs to be serializable. Member variables need to be marked as…
Roman Nikitchenko
  • 12,800
  • 7
  • 74
  • 110
10
votes
1 answer

Jenkins ignores trend graph configuration

I've set up Jenkins as a service on my Windows 7 developer PC in order to provide rational arguments to why we should use Jenkins and not Bamboo in the company. I've installed the 'Analysis Collector Plugin':…
10
votes
1 answer

Verify that Java classes implement toString()

As a part of the regular static analysis of my program, I would like to check that classes are likely to have sane toString() methods. Probably not that every class implements them, but perhaps that no instantiable concrete class uses Object's…
Michael Ekstrand
  • 28,379
  • 9
  • 61
  • 93
10
votes
1 answer

Generate warnings for autoboxing use

I would like to generate warnings for ALL autoboxing and unboxing. Has anyone found an effective way? Eclipse catches basic autoboxing errors: eg. Integer i = null; i++. But fails on anything complex, and isn't really what I'm after. I've looked at…
David Lavender
  • 8,021
  • 3
  • 35
  • 55
9
votes
1 answer

PMD plugin fails with Java 14: Unsupported targetJdk

I am trying to have a pom.xml file with PMD plugin integrated into build stage. PMD version 3.13.0 Oracle JDK 14
Yan Khonski
  • 12,225
  • 15
  • 76
  • 114
9
votes
1 answer

Which is the highest priority in PMD?

Maybe it's just me, but I can't find information which is the highest priority in PMD: 1 or 5? Because of http://pmd.sourceforge.net/running.html and the mention of the command line parameter -minimumpriority I think 5 is the highest and 1 is the…
cringe
  • 13,401
  • 15
  • 69
  • 102
9
votes
2 answers

PMD UselessParentheses violation

I have the following Java method: private int calculate() { return (bytes[0] & 0xff) + ((bytes[1] & 0xff) << 8); } PMD complains on this code with "UselessParentheses" violation. I've reviewed operator precentence rules and I still don't see…
Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
9
votes
3 answers

Reasoning behind ArrayIsStoredDirectly rule of PMD

PMD has a rule called ArrayIsStoredDirectly in the Sun Security ruleset: Constructors and methods receiving arrays should clone objects and store the copy. This prevents that future changes from the user affect the internal functionality. Here is…
Wilhelm Kleu
  • 10,821
  • 4
  • 36
  • 48
9
votes
1 answer

Is it possible to detect autoboxing in a PMD rule?

The Apache Thrift code generator generates classes that look something like this. The numCpus field is nullable, but since it's held as a value type there's another isSet field to determine if it's really set: public class TaskConfig extends…
kevints
  • 91
  • 3
9
votes
1 answer

PMD, checkstyle and findbugs android setup

how can I setup PMD, Findbugs and Checkstyle static code analysis tools for an Android project using the latest version of gradle? I tried several thing but I don't manage to make them work. Thanks
Juan Yanez
  • 105
  • 1
  • 6
9
votes
3 answers

Why is avoiding Boolean instantiation a good idea?

PMD is warning me to avoid Boolean instantiation (for efficiency reasons). I have something like this Boolean variable = new Boolean(somestringIGotRepresentingABoolean); And I'm supposed to use this Boolean variable =…
dertoni
  • 1,763
  • 2
  • 24
  • 47
8
votes
1 answer

CheckStyle, FindBugs, and PMD configurations without overlap

At my company we started using CheckStyle, FindBugs, and PMD to check our code quality and unify our programming styles. These tools are very effective but unfortunately they have some overlapping rule sets. Are there configurations available online…
Dennis Laumen
  • 3,163
  • 2
  • 21
  • 24
8
votes
2 answers

PMD message "Avoid using java.lang.ThreadGroup; it is not thread safe"

Question: Why the maven PMD plugin is giving me the following warning for the line of code below: Warning: Avoid using java.lang.ThreadGroup; it is not thread safe Code (second line): Calendar cal = Calendar.getInstance(); java.sql.Date endDate =…
8
votes
3 answers

Ease of writing custom rules in (Java) static code analysis tools

At present I am working for a group where source code (Java) for multiple projects have to be analysed by static code analysic tools But I would like to write custom rules that I can add to the existing set of rules provided by the tool (the rules…
Manoj
  • 113
  • 1
  • 2
  • 7
8
votes
1 answer

Is there a way to lint incompatible Java API references with PMD, Checkstyle, SpotBugs, etc?

We are currently using Java Compiler 11 and deploy our main artifacts to Java 11. No problem here. Unfortunately, a service we use only supports Java 8 so we compile some of them targetting Java 8. No problem here. Our issue is that developers…