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.
836
questions
0
votes
0
answers
17
views
PMD - Implement nullcheck for all findById methods
I am trying to write rule in PMD that will highlight code where dao.findById is being used without null check.
So code below will stop the build and alert the programmer:
final var isObjectPresent = ...
1
vote
1
answer
58
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
80
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
19
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
0
answers
16
views
Static Analysis: Is there a parser for SpotBugs/PMD outputs?
Motivation
My ultimate goal is to build an open-source CLI tool that automatically fixes common programming mistakes. I know modifying code is difficult and risky, so...
My medium-term goal is to ...
0
votes
1
answer
29
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
0
answers
21
views
PMD Security Rules
i have two questions regarding the development of pmd rules.
I am currently trying to add several security rules to pmd. These shall mark violations against the technical guidline provided by the ...
0
votes
2
answers
62
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
0
answers
16
views
Any way to calculate code coverage / other code analysis api on a specific git commit for maven spring project?
i'm using jacoco for code coverage with maven project. jacoco calculate the coverage for the whole project but need to calculate coverage only on the changes classes within the git commit ? any idea ?
0
votes
1
answer
187
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
46
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
32
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 (" ...
0
votes
0
answers
57
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?...
0
votes
0
answers
33
views
PMD ruleset for a project
I'm trying to find the following pmd rules for a project:
Coupling complexity
number of lines per method
duplication of code
2
votes
2
answers
62
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
49
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
48
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-...
0
votes
0
answers
29
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
0
answers
23
views
PMD Rule<rule ref="category/java/errorprone.xml/CompareObjectsWithEquals"/> doesn't work completely. Any workaround?
PMD Rule doesn't work completely
private Integer globalVariable;
boolean bar(Integer chunk2, Integer page2) {
return chunk2 == page2; // PMD is detected
}
boolean bar(Integer chunk2, Integer page2) {...
0
votes
1
answer
39
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&...
0
votes
1
answer
35
views
PMD error: AccessorMethodGeneration when overriding some method in Lombok Builder
I have the following class that should be built with Lombok @Builder:
import lombok.Builder;
import lombok.Getter;
@Getter
@Builder(toBuilder = true)
public class Foo {
private String myName;
...
2
votes
2
answers
49
views
NoSuchElementException infinite loop vs. pmd DD-anomaly
I'm kinda new to programming and very new to gradle and the pmd-plugin, so please have mercy.
If the user enters a number, scanner.nextLine() will throw a NoSuchElementException in every iteration ...
0
votes
1
answer
38
views
Deserializing PMD output with Jackson
I'm trying to deserialize the output of PMD using Jackson. Specifically, I want to obtain a list of violations and their data, which PMD gives me in the following form:
<pmd-cpd>
<duplication ...
0
votes
0
answers
65
views
Non-resolvable PMD Violation: These nested if statements could be combined
For the below code, I am getting a PMD violation "These nested if statements could be combined." that is causing the build pipeline to fail
if(request != null && ...
1
vote
1
answer
82
views
Jenkins PMD details from docker: Copying the source file failed
I'm running Jenkins maven task inside docker image. My task generates pmd.xml which is then parsed by Jenkins plugin.
The problem is that path inside docker image is different that Jenkins workspace. ...
0
votes
0
answers
24
views
PMD Rule Set Using Eclipse Warnings
Is there a way to get Eclipse warnings in PMD? Right now, I'm using gradle to build (alternatives are a no-no). Many of Eclipse's warnings I'm having trouble finding in PMD.
-1
votes
1
answer
46
views
How do I create a custom PMD rule to check if an instance of DSLContext is begin referenced in a loop?
I am trying to create a custom PMD rule that will cause a violation if an instance of org.jooq.DSLContext is being referenced in a loop.
I am completely new to PMD so I have no idea where to start.
...
0
votes
0
answers
32
views
Is mmap support section map?
I want mmap a memory block in user space to read/write, mmap with a file. The size of the memory block is more than 12M. To improve the performance,i want map with section, but i trace the linux ...
0
votes
0
answers
31
views
Aggregate PMD reports with Kordamp gradle project
I've got a multimodule gradle project here https://github.com/prule/kordamp-template-project
I'm using the Kordamp plugins - hopefully - with the default/recommended layout.
PMD reports a couple of ...
0
votes
0
answers
41
views
Regarding PMD Rules in SOQL
I am facing below PMD error :
"Query parameters should be validated so queries are not performed if their parameters are empty"
I tried below approach but the issue is still not resolved....
0
votes
0
answers
29
views
PMD - How to suppress violations for a class but not for methods in it
The class 'XXX' has a total cognitive complexity of 56 (highest 14). (rule: Design-CognitiveComplexity)
I have this PMD error that I want to throw out but only for the class part, meaning that if a ...
-1
votes
1
answer
777
views
Why the entity class is showing pmd warning "Class is suspected to be a DataClass"
I have a class User as given below
@Entity
public class User {
@Id
@GeneratedValue
private Long primaryKey;
private String name;
// some other fields, default constructor, All ...
0
votes
0
answers
19
views
sfdx cli scanner is reporting issue even though FLS check is there
We have a common utility class where all the FLS checks are made but sfdx cli scanner is reporting issues under ApexCRUDViolation rule for classes where the FLS check is already there.
If the FLS ...
0
votes
0
answers
344
views
Can sonarlint be used in place of checkstyle?
I am working on a project which already has sonarqube integrated. Now, we want to have a plugin in our local IDE(with some sort of XML) so that everyone in the team can have the same set of rules.
I ...
0
votes
1
answer
218
views
PMD - confusion between maven, sonarqube and java versions
Small question regarding PMD please.
As I am writing this (June 2021), the latest maven pmd plugin is:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
...
1
vote
1
answer
249
views
PMD maven plugin: How to specify a different ruleset for tests?
I need to configure the PMD maven plugin to scan test source code with less strict checks comparing to production code.
Is there a way to do it?
0
votes
1
answer
336
views
PMD: How to exclude a rule imported from a ruleset
We are using PMD to assess the quality of our "main" source code. We have our own customized ruleset that includes some category rulesets and excludes some specific rules.
Simplified example,...
0
votes
1
answer
73
views
Running PMD for C++ project in eclipse
I am using eclipse based development IDE called STM32Cube IDE V1.5.1. I have installed PMD plugin into same. PMD Plugin version 4.24.x & PMD Version 6.35.x.
On most of the links it was found that ...
1
vote
0
answers
36
views
How to enable pmd specific tasks as a separate task and not on the build task
I want to run pmdMain, pmdTest only as a custom task (say ./gradlew pmd) and not part of the build task (i.e ./gradlew build). This is how I am enabling pmdMain right now, but how do I do this for ...
1
vote
0
answers
124
views
Maven build failing in Flex PMD Report report generation phase
I'm getting the following error while executing the goal com.adobe.ac:flex-pmd-maven-plugin:1.2:report (run-flexpmd-main) in one of the sub modules of our project.
Failed to execute goal com.adobe.ac:...
0
votes
1
answer
23
views
RapidClipse and PMD plugin
How can i install a working PMD plugin in RapidClipse 10.4. I allready tried the 2 plugins from the marketplace but none was able to automatically run after saving a file.
0
votes
2
answers
149
views
I get this error running PMD from salesforce CLI, "ERROR running scanner:run: Attempted to resolve unregistered dependency token: "RuleManager""
Can anyone help me with this. Im using Mac. I cant find the location of the rulemanager. Please see error below
Lxxxxxxx:pmd-bin-6.34.0 xxxxxx$ sfdx scanner:run pmd --target /usr/src --category ...
1
vote
1
answer
35
views
Seeking a static instance of SecureRandom rule in PMD
I am researching PMD repo in the following link
repo link
So what I am looking for is a rule that would make sure that
you should only be using the primed static SecureRandom instance
( this is mainly ...
0
votes
1
answer
36
views
XPATH - Can I retrieve the type of a variable with an XPATH query for eclipse-pmd plugin?
I'm currently working on custom rules for the pmd plugin on eclipse.
Is it possible to retrieve, with an XPATH query, the type of a variable?
Thank you in advance !
0
votes
0
answers
27
views
PMD Xpath to check presence Relational Expression
Wrote below Xpath , which to i want extend to include "<", ">=" etc.
//RelationalExpression[@Image=">" and
descendant :: PrimaryExpression/PrimaryPrefix/Name[@...
1
vote
0
answers
182
views
How to add custom Java rules for Eclipse PMD plugin?
I’m using the pmd plugin on eclipse and I need to create my custom rules. I created my java class dependent on the AbstractJavaRule class and created my ruleset. But I can't import everything into pmd ...
-1
votes
2
answers
72
views
Static Analysis tool to catch self-invocation bypassing Spring cache @Cacheable method
I understand that this is because of the way proxies are created for handling caching, transaction related functionality in Spring. And the way to fix it is use AspectJ but I donot want to take that ...
0
votes
0
answers
63
views
PMD Maven Plugin ignores exclude properties Values for inner class
I'm using PMD v3.12 in my current project.
I have a POJO with some properties:
public class Person {
private String name;
private String surname;
private String state;
private String zip;
...
0
votes
0
answers
367
views
How do I tell the maven pmd plugin to ignore 'Avoid unused private fields such as ...` when using lombok?
I have a simple domain class like this...
@Getter
@Setter
@ToString
public class Address
{
private String purpose;
private String line1;
private String line2;
....
}
But when I run ...
1
vote
1
answer
157
views
Setting XPath violation suppressions in PMD
I'm setting up custom rules in PMD but I am having trouble getting the XPath suppressions to work and without using deprecated features. I am using PMD 6.32.
My rule is to modify the rule ...