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

Custom PMD rule with Gradle

I would like to use the gradle PMD plugin in an enterprise project which is built with gradle. I have a pmd_rules.xml file which already works, but I can't add own java rules (I get a class not found exception). I followed the tutorial on it's…
Manuel
  • 496
  • 6
  • 20
8
votes
2 answers

@SuppressWarnings more than one rule not working

PMD and SonarQube a nice tools but I have problems trying to suppress PMD warnings. We use Lombok a lot in our project, so many of the model classes have a: @SuppressWarnings("PMD.UnusedPrivateField") as an class-level annotations. This works…
Morten Frank
  • 219
  • 1
  • 3
  • 10
8
votes
1 answer

UnnecessaryLocalBeforeReturn - why it's bad?

I started my adventure with Sonar ;) Sonar with it's default configuration has PMD UnnecessaryLocalBeforeReturn error set on major level. List filtered = em.createQuery(query).getResultList(); return filtered; It means for me that I…
zimi
  • 1,586
  • 12
  • 27
8
votes
1 answer

code analyzer specifically for gwt code?

I have been going through code analyzers like pmd, findbuigs. They cover many cases and seem to be great to use. But wanted to know if there is any code analyzer specifically for gwt code?
Saurabh
  • 445
  • 6
  • 19
7
votes
1 answer

PMD with Maven - How to disable one rule within a ruleset?

I have PMD running via Maven 2. Right now I have all the rulesets in place to see what gets generated (see code below). I'm going through and fixing things that make sense to me to fix. However, there are cases such as in the "optimizations"…
Bellini
  • 332
  • 1
  • 6
  • 11
7
votes
3 answers

Explanation and fix for Possible null pointer dereference of

Code review tool is complaining Possible null pointer dereference of safeScanWarnings in saveSafeScan(...) At the line if (safeScanWarnings != Null & safeScanWarnings.size() > 0) I am wondering how is this possible? Is this because we are returning…
Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
7
votes
6 answers

Java error: New exception is thrown in catch block, original stack trace may be lost

try { // code which throws exception. } catch (SQLException sqlex) { logger.error("Custom message", sqlex); **throw new CustomApplicationException("Custom message", sqlex);** } In the above example, on the bold line, I am getting PMD…
user613114
  • 2,731
  • 11
  • 47
  • 73
7
votes
2 answers

Prohibit brackets after method signature in Java code

In my project recently I've encountered code that compiles perfectly fine, however is very surprising to any reader and should not pass static analysis. class BracketsAfterMethodSignature { Object emptyArray()[] { return new Object[]{}; …
Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
7
votes
2 answers

how to exclude classes from pmd rule by regexp

Is there a way to exclude classes from PMD rule by class name pattern? I'm looking for sth like: .*Test\.class I'm aware of…
Kragh
  • 170
  • 1
  • 13
7
votes
4 answers

Suppress warnings from CPD for C/C++ code

We are using PMD Copy Paste Detector (CPD) to analyze our C and C++ code. However, there are a few parts of the code that are very similar, but with a good reason and we would like to suppress the warnings for these parts. The documentation of PMD…
Arno Moonen
  • 1,134
  • 2
  • 10
  • 28
7
votes
1 answer

How to lock maven plugin version

How can I lock the version of a Maven plugin I want to use? I have the PMD plugin configured like so: org.apache.maven.plugins maven-pmd-plugin
Greg
  • 1,339
  • 2
  • 13
  • 18
7
votes
2 answers

How to tell PMD to ignore @PostConstruct Methods for unused Code

we have a project which is checked by PMD for violations of e.g. unused private methods. Our problem is that we don't know if it is possible to ignore private Methods which are annotated with @PostConstruct. The rule is defined as following:
moz987
  • 161
  • 7
7
votes
1 answer

Is there a Checkstyle/PMD rule "Non-abstract classes should not be named AbstractXXX"?

The Java project I'm working on uses a combination of code analysis tools: PMD, Checkstyle and FindBugs. These pick up on plenty of bugs, style issues etc. but one often slips through the net: public class AbstractBadlyNamedClass { // Not abstract! …
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
7
votes
1 answer

Maven PMD plug-in not generating a report with 'mvn site' command or 'pmd:pmd'

I am reading an interesting tutorial here: http://www.avajava.com/tutorials/lessons/how-do-i-generate-pmd-and-cpd-reports-for-a-site.html?page=1 This tutorial shows how to use Maven to run the open-source static-analysis tool, PMD, and to see the…
user3808269
  • 1,321
  • 3
  • 21
  • 40
7
votes
1 answer

How to find PMD Rulesets names in Gradle >2.0

In Gradle's Java projects we can use PMD via pmd plugin. To configure the rules which we want to use can do it in two ways: ruleSetFiles - The custom rule set files to be used. See the official documentation for how to author a rule set file.…
Xelian
  • 16,680
  • 25
  • 99
  • 152