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.
857
questions
0
votes
0
answers
17
views
Can I check file existence using PMD rules?
I want to check if files existence using PMD rules, such as (gitignore, version, readme, . . . ) files.
What is the recommended way to do so?
I searched for the java rules and xpath rules in pmd but I ...
1
vote
1
answer
47
views
Using XPath for PMD, is there a way to account for the value of a variable in a method call?
For example:
String user = "Daniel";
String result = doSomething(user);
I know I can find every occurence of doSomething(user) with //MethodCall[@MethodName = "doSomething"]/...
2
votes
2
answers
57
views
Xpath expression not working to identify print statements in java code using eclipse-PMD
I want to identify print statements that are not inside the conditional statements (i.e., to check if the print statement has any if statement as its ancestor)
few test cases are as follows :
...
1
vote
1
answer
638
views
Static Analysis Failed. Error Details: PMD Command Failed! Enable "Show StdErr" setting for more info
I have installed APEX PMD extension in vscode. I have added C:\Program Files\Java\jre1.8.0_202\bin\java to Sys env Path variable. I have downloaded pmd-bin-7.0.0-rc3 and added C:\pmd-bin-7.0.0-rc3\...
0
votes
1
answer
43
views
Xpath expression that takes a method parameter is being used only in the log call
I want to create a PMD rule using the XPATH expression with the following scenario:
When a parameter of a method is only used in log like log.info, log.error, log.warn or log.debug from @Slf4j I want ...
1
vote
0
answers
37
views
How to resolve Xpath expression for eclipse-pmd java detecting strings in the method calls
I am working on a Java project that uses PMD-eclipse plugin to check the code quality. I want to write a custom PMD ruleset that can identify hardcoded variables in the code, such as strings, numbers, ...
0
votes
0
answers
34
views
Why is pmd seemingly not scanning the right directory
After going through the logs when pmd is ran through maven i can see that the correct langauge (javascript) and rules seem to be getting applied but it says no errors or equivalent found when i ...
0
votes
0
answers
17
views
PMD Custom Java Rule not invoked
I am trying to create a custom Java rule in PMD, but looks like it is not being invoked.I have placed the rule. xml and the custom class files at the appropriate locations inside PMD lib folder and ...
1
vote
1
answer
53
views
PMD in gradle how to exclude directories
So I have set up PMD with in my gradle project.
I want to exclude certain directories from the scan?
How can i do that, this is my gradle setup
pmd {
toolVersion = "6.48.0"
...
0
votes
1
answer
97
views
NCSS count doesn't change
I'm getting the error that I have 29 ncss line count, but after adding comments it doesn't remove it in pmd. Why is that, do I need to add more comments?
-2
votes
1
answer
153
views
Avoid the use of value in annotations when its the only element
"UnnecessaryAnnotationValueElement: Avoid the use of value in annotations when its the only element"
@Query(value = "SELECT t FROM IntraPaymentTransaction t WHERE exchangeBuyAmount....
0
votes
0
answers
33
views
How do I suppress a PMD false positive result in Visualforce?
When using PMD scanning in Apex, you can suppress false positive results to exclude them from report output using annotations or same-line comments.
In a Visualforce page containing markup, how do you ...
0
votes
0
answers
46
views
Baseline file support for pmd
It is hard to fix all pmd errors on an existing large Java project. This may cause regressions, and many refactors, changes everywhere.
I'd like to refer to the solution in Android lint tool, Android ...
1
vote
1
answer
174
views
Overriding default Apex PMD rules
I'm trying to customise a PMD ruleset to identify violations of our code style conventions, for Salesforce Apex code.
Most of our conventions follow the default generally-accepted conventions in the ...
0
votes
0
answers
69
views
How to set the callback for tx_pkt_burst in a multi-process dpdk 19.11 application for secondary process
I have a multi process application that uses af_packet driver.
From dpdk 19.11 it was changed how the secondary process is configured:
first change: the second process needs to be started with the ...
0
votes
1
answer
75
views
Using XPath in PMD to find duplicate expressions
I want to use PMD to find Common Subexpression of the form
z = a +b;
q = a +b;
for Java code.
I know the CPD tool exists for things like this but there I will also receive copied functions etc. that ...
0
votes
0
answers
344
views
'pmd.bat' is not recognized as an internal or external command, operable program or batch file
I want to install PMD errors in my PC I did all the steps but getting this error
'pmd.bat' is not recognized as an internal or external command,
operable program or batch file.
how to override it.
0
votes
1
answer
148
views
When 3rd party jar added in PMD Gradle classpath causes 'java.lang.ClassNotFoundException: net.sourceforge.pmd.PMD'
I tried to add 3rd party dependencies in gradle.properties as below
dependencies {
pmd fileTree(dir: "${lib}/aspectj-1.9.4", includes: ['*.jar'])
// OR below
// pmd '...
0
votes
0
answers
26
views
Running into ArrayIndexOutOfBoundsException issues with PMD
I am trying to build a spring-boot project with pmd integrated in gradle and running into ArrayIndexOutOfBoundsException for lot of test cases. Even when I run single test case in debug mode to ...
-1
votes
1
answer
291
views
Is SonarQube sufficient for static code reviews? [closed]
My applications are based on Java, Kotlin and React.
Besides SonarQube there are other popular tools like:
Amazon CodeGuru helps you improve code quality and automate code reviews by scanning and ...
1
vote
1
answer
203
views
Plugins not running in maven project
In my pom.xml i have these plugins: checkstyle, pmd and spotbugs. None is running during the lifecycle.
Here is my pom:
<?xml version="1.0" encoding="UTF-8"?>
<project ...
0
votes
2
answers
376
views
Running PMD in GitLab CI Script doesn't work unless echo command is added after the script runs
This is an interesting issue. I have a GitLab project, and I've created a .gitlab-ci.yml to run a PMD that will scan my code after every commit. The ci.yml file looks like this:
image: "node:...
1
vote
1
answer
75
views
PMD Ignore Spring Field Injections in gradle config
Currently I have several Controllers that inject dependencies through a field marked with @Autowired. When I try to run gradle build the following violations come up.
These all correspond to the ...
0
votes
1
answer
547
views
DPDK Multi-process; Kill a primary process and restart as a secondary doesn't work
I'm already running up to 4 DPDK processes next to each other without any issues and I can also restart secondary processes successfully.
I read here in end of the symmetric multi-process section, ...
1
vote
1
answer
180
views
AvoidDuplicateLiterals pmd error for @MethodSource
I am getting AvoidDuplicateLiterals pmd violation for using reference "abc" multiple times in different Method source.
@ParameterizedTest
@MethodSource("abc")
public void ...
0
votes
2
answers
163
views
write regex for PMD custom rule
i created the following custom rule for PMD but when i run it, i get an error. if i replace the regex with a trivial regex like "a", it works. cannot understand what's wrong.
<?xml ...
1
vote
1
answer
180
views
PMD issue and Java --version
I would like to know if this message is correct, when I write in cmd
java --version
I add it in the path
I have some troubles with Salesforce extension PMD and shows the following message :
0
votes
0
answers
12
views
How to modify the API interface usage of PMD to directly detect the character array generated by the target code file
Recently, I want to make some modifications to PMD, so that it can directly read character arrays for code detection, eliminating the step of reading files. Is there any way to modify or actually PMD ...
0
votes
1
answer
94
views
installing PMD 6.49.0 to windowsp
Download instructions say to install to C:\pmd-bin-6.49.0.
Can this be copied to "C:\Program Files\pmd-bin-6.49.0" instead?
Our network policy generally forbids creating folders off the root....
0
votes
1
answer
504
views
Dpdk pmd vdev as secondary process
I implementing the Poll Mode Driver(PMD) memif(vdev=net_memif) virtual device in application. Specificly, I have to run memif as a client in secondary process.According to the Dpdk pmd multiprocess ...
0
votes
0
answers
197
views
No rules found post PMD upgraded to PMD 6.48
SEVERE: Cannot load ruleset D:\Program Files\Jenkins\workspace\Devops\TestWarningNextGen/rule/apex/ruleset.xml: Cannot resolve rule/ruleset reference 'category/apex/codestyle.xml/...
1
vote
0
answers
60
views
Getting qualified type names of parameters (and defined classes) from pmd's Java ast
I need to get the qualified name of classes and method parameters in order to build a consistent way of addressing methods across different libraries.
For the sake of illustration, a very artificial ...
0
votes
1
answer
326
views
Why does codacy give `Unnecessary block` error for function declaration?
We are using codacy for static code analysis. On pushing a change to the js file, where we are declaring a function that returns an object, it is giving the below error.
Internally, codacy tells us ...
5
votes
2
answers
1k
views
java.lang.NoSuchMethodError thrown by Maven PMD Plugin 3.18.0
I am working on a long running multi-module Maven Java project. I tried to update the PMD plugin from 3.17.0 to 3.18.0, but I get a java.lang.NoSuchMethodError from PMD almost immediately. The 3.17....
0
votes
2
answers
462
views
How to download pmd_ruleset file for maven pmd plugin?
I am trying to add maven pmd plugin in my codebase. added below code in pom file but not sure where to download the pmd_ruleset.xml file.
<plugin>
<groupId>org.apache.maven.plugins</...
1
vote
1
answer
206
views
No Warnings are getting generated for maven-pmd-plugins
I am using maven-pmd-plugin, I have added this plugin in my parent pom, I have added some unused variable in my code but still it is not able to throw any warnings, everytime it is creating an empty ...
1
vote
2
answers
472
views
Spring Boot @Autowired - checkstyle / pmd / spotbugs rule to warn on non-interface usage
Having recently been bit by Spring CGLib vs JDK Dynamic proxying issues in a Spring Boot application (that when run on a Mac seems to use CGLib where as the same app when run on Linux is using JDK ...
0
votes
0
answers
397
views
RX packets handle takes too long DPDK
I'm developing my own DPDK PMD for an ethernet device which receives/sends packets through PCIe.
In order to develop my PMD, I'm using l2fwd application, which forwards packets from a physical port to ...
0
votes
2
answers
76
views
PMD: Is there a way for rule writer to get the package name of the current node?
Well I have the Node, and I can get what class Name it in, but I cannot get package of this class.
Is there any way to achieve this?
Thanks!
BTW: I'm talking about PMD, so people who don't know what ...
0
votes
1
answer
74
views
How to get attribute from xml by PMD
I write a rule for xml, and it can find the line matched of xml.
xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:sofa="http://schema.alipay.com/sofa/schema/...
0
votes
1
answer
358
views
PMD rule for java to avoid using @Autowired annotation on class fields- to not use field injection
I want to have a pmd rule for my java project which will disallow field injections in Spring(want to use injection by constructor instead). is there any pmd rule for it, or can I create some to have ...
0
votes
1
answer
1k
views
How to add custom java pmd rules to gradle project using gradle-pmd-plugin?
During working on project arch4u-pmd we made several java-based pmd rules, configured them in XML-based ruleset our-rules.xml, and published it as a plain java lib/artifact (io.github.abc:my-pmd-rules:...
0
votes
1
answer
273
views
Use of Deprecated PMD rules
We've recently picked up PMD on our Salesforce project to help with our Apex code quality analysis. We've implemented a couple of rules, but have seen that most of the really valuable-looking rules (...
0
votes
1
answer
187
views
pmd or spotbugs rule to catch connection leaks?
Does anyone know the name of the PMD rule or Spot bugs detector which catches connection leaks like one here
try (PreparedStatement st_stage_CF = **Global.getConnection().**prepareStatement (" ...
2
votes
0
answers
263
views
How i can integration pmd in gitlab?
I didn't find any mention of this in the official documentation, but I came across an article where it says that there is a possibility, but it is not described
Does anyone have articles on this topic?...
2
votes
2
answers
216
views
How to prohibit usage of classes with certain annotation
In our organizations we've got several microservices and lots of libraries.
Some libraries define "public" classes that are not intended for public usage - only inside library in multiple ...
0
votes
1
answer
253
views
Nested try/catch inside block and PMD rule
I'm trying to refactor this code cause PMD throwing Failure:PreserveStackTrace:3, the main problem is how I can collapse exception e1 into e2, is it anti-pattern right now?
I thinking about extract ...
0
votes
1
answer
130
views
Why is PMD give different results for Eclipse and Gradle?
I am using the eclipse-pmd plugin, and I am also using PMD via the following Gradle configuration:
plugins {
id 'pmd'
}
pmd {
consoleOutput = true
ruleSets = []
ruleSetFiles = files("pmd-...
1
vote
0
answers
300
views
Apex PMD SuppressWarnings breaks Prettier document formatting
I've recently installed PMD and it's working... however, when I try to suppress a specific warning:
@SuppressWarnings('PMD.EmptyStatementBlocks')
if (a == b) {
// empty statement block
}
This works ...
0
votes
1
answer
131
views
How can PMD HTML Report's Error Description Link Show Local Folder
I am using PMD source code analyzer (PMD) for my java web project through ant task. The computer is offline (not connected to the Internet). Part of ant task is as follows:
<target name="pmd&...