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
6
votes
3 answers

How to avoid this PMD error - The String literal "TEST" appears X times in this file;

How can I avoid the PMD error in my Java code? public enum testEnum { TEST1(1L, "TEST", "random1"); TEST2(2L, "TEST", "random2"); TEST3(3L, "TEST", "random3"); TEST4(4L, "TEST", "random4"); TEST5(5L, "TEST", "random5"); …
user4763173
6
votes
3 answers

PMD exclude-pattern with gradle

I'm attempting to create some exclude patterns for a PMD task in Gradle. My task is generated in the next way: /* Allows generation of pmd config */ allprojects { apply plugin: 'pmd' } gradle.projectsEvaluated { subprojects.each() {…
Guillermo Merino
  • 3,197
  • 2
  • 17
  • 34
6
votes
2 answers

Why does comparing enums using == cause a PMD warning?

The following compares two enum values using ==: MyEnum enum1 = blah(); // could return null MyEnum enum2 = blahblah() // could return null if (enum1 == enum2) { // ... } But PMD gives a CompareObjectsWithEquals warning on line 3: Use…
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
6
votes
2 answers

How to run Checkstyle, Findbugs, or PMD programmatically on file *content*

I'm writing a utility which checks Atlassian Stash pull requests for modified files - the goal is to run each Java file through Checkstyle (or Findbugs, or PMD), and then have the plugin comment on each line with problems. To accomplish this, the…
Mike Cialowicz
  • 9,892
  • 9
  • 47
  • 76
6
votes
2 answers

Avoid Literals In If Condition

This part of code is rejected by pmd in sonar: public String getFoo() { String foo = System.getProperty("foo"); if (foo == null) { foo = System.getenv("foo"); } else if (foo == null) { foo = "defaultFoo"; } …
Walery Strauch
  • 6,792
  • 8
  • 50
  • 57
6
votes
2 answers

Maven and code metrics: check for existence of a test case for each class

Is there something that can be used in Maven to automate this kind of check? I'm seeing checkstyle and PMD but I'm not finding this feature. Basically I'd like the build to fail if there's a class A and there's not an ATestCase. I know, it is not a…
Andrea
  • 2,714
  • 3
  • 27
  • 38
6
votes
4 answers

How detect string concatenation in logger statements?

Is there a way to configure the Checkstyle, PMD, or FindBugs Maven plugins to detect code like this: logger.debug("string" + stringVariable); Instead of: logger.debug("format string {}", stringVariable);
Cherry
  • 31,309
  • 66
  • 224
  • 364
6
votes
2 answers

PMD+Maven+JAVA Error:: Can't find resource rulesets/comments.xml. Make sure the resource is a valid file or URL or is on the CLASSPATH

while adding a custom ruleset of PMD , maven is producing an error -net.sourceforge.pmd.RuleSetNotFoundException: Can't find resource rulesets/comments.xml.Make sure the resource is a valid file or URL or is on the CLASSPATH. For others rule sets…
The PowerHouse
  • 560
  • 14
  • 29
6
votes
5 answers

Installing PMD 5.0.4 in Eclipse

Can anybody tell me how to install PMD in Eclipse. I have downloaded PMD 5.0.4 from the following link: http://sourceforge.net/projects/pmd/files/latest/download?source=files When I add this archive file in Eclipse install option I am getting an…
JPS
  • 2,730
  • 5
  • 32
  • 54
6
votes
2 answers

What is the full form of PMD?

I am using PMD in my Java project for code review. Just want to know what the acronym "P.M.D." stands for. I searched on Google but could not find anything. Does anyone know?
Anand
  • 20,708
  • 48
  • 131
  • 198
6
votes
2 answers

Intellij IDEA - How to disable automatic plugin update

Whenever you hit 'the check for update' button, IntelliJ checks for IDE update and starts by checking and updating all your active plugins. The point is that I use a pretty crooked plugin which only works for me in an old version (a release from…
Saad Benbouzid
  • 502
  • 6
  • 16
6
votes
1 answer

Can't use custom ruleset in maven-pmd-plugin 5.0.2

I want maven-pmd-plugin to include rulesets that I specify and exclude some rules (specifically, UselessParentheses) Just like described in documentation, I placed the following in pmd.xml that is parent for all modules:
Andrey Regentov
  • 3,687
  • 4
  • 34
  • 40
6
votes
2 answers

How to suppress PMD warnings during a Maven install

I have a Java project that is built using Maven, thus my build process is defined in the pom.xml file of the project. My development team uses a variety of plugins to check the quality of our source code; one such plugin uses PMD to check the…
ecbrodie
  • 11,246
  • 21
  • 71
  • 120
6
votes
4 answers

PMD-Plugin in Eclipse/Juno not installable through marketplace

I recently upgraded from Eclipse (for Java/EE developers, x64) "Indigo" to "Juno". Unluckily the PMD-Plugin (http://marketplace.eclipse.org/content/pmd-eclipse) does not seems to be available for this product. I was unable to find another way of…
Robert Heine
  • 1,820
  • 4
  • 29
  • 61
6
votes
2 answers

DD anomaly, and cleaning up database resources: is there a clean solution?

Here's a piece of code we've all written: public CustomerTO getCustomerByCustDel(final String cust, final int del) throws SQLException { final PreparedStatement query = getFetchByCustDel(); ResultSet records = null; …
Simon Brooke
  • 386
  • 4
  • 7