pmd

PMD rule “Use Proper Class Loader” explaination?

五迷三道 提交于 2019-12-01 09:16:57
There is the following PMD rule: Use Proper Class Loader (Critical) In J2EE getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead. Can somewhat explain more what they are thinking of? What exactly means "J2EE" environment here? J2EE environment refers to the Java Enterprise Edition. Here, you do not run your program as a standalone application on the JVM, but instead, you let the JEE Application Server (e.g. Glassfish or Tomcat) to run it for you. Application Servers provide a lot of different ways to run your program, for example they offer

Share specific PMD rulesets across multi module maven project

巧了我就是萌 提交于 2019-12-01 06:40:44
I'm trying to share the same pmd configuration across all my submodules. I'm looking for the best way to achieve that I thought that I could place it in the parent project, like I did it for checkstyle plugin Parent pom.xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.9.1</version> <configuration> <configLocation>/src/main/config/checkstyle.xml</configLocation> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>2.7.1</version>

PMD rule “Use Proper Class Loader” explaination?

做~自己de王妃 提交于 2019-12-01 06:21:54
问题 There is the following PMD rule: Use Proper Class Loader (Critical) In J2EE getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead. Can somewhat explain more what they are thinking of? What exactly means "J2EE" environment here? 回答1: J2EE environment refers to the Java Enterprise Edition. Here, you do not run your program as a standalone application on the JVM, but instead, you let the JEE Application Server (e.g. Glassfish or Tomcat) to run it

Share specific PMD rulesets across multi module maven project

坚强是说给别人听的谎言 提交于 2019-12-01 04:42:38
问题 I'm trying to share the same pmd configuration across all my submodules. I'm looking for the best way to achieve that I thought that I could place it in the parent project, like I did it for checkstyle plugin Parent pom.xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.9.1</version> <configuration> <configLocation>/src/main/config/checkstyle.xml</configLocation> </configuration> </plugin> <plugin> <groupId

java :Why the Local variable should be declared final [duplicate]

↘锁芯ラ 提交于 2019-12-01 04:27:47
Possible Duplicate: Is there any performance reason to declare method parameters final in Java? Why would one mark local variables and method parameters as “final” in Java? I am using PMD to see the code violations. Inside a webService Method, I have this below code public ServiceRequest getData() { Status status = new Status(); // code } What PMD is suggesting me is that, this local variable status could be declared as final. My question is, making it final would result in any performance improvements or if not what benefits the code could get? Nick Garvey Taken from the following article:

[sonarqube的使用] sonarqube安装

纵然是瞬间 提交于 2019-11-30 12:55:22
一 . SonarQube代码质量检查工具简介 Sonar (SonarQube)是一个开源平台,用于管理源代码的质量 Sonar 不只是一个质量数据报告工具,更是代码质量管理平台 支持Java, C#, C/C++, PL/SQL, Cobol, JavaScrip, Groovy 等等二十几种编程语言的代码质量管理与检测。 Sonar可以从以下七个维度检测代码质量,而作为开发人员至少需要处理前5种代码质量问题。 不遵循代码标准 sonar可以通过PMD,CheckStyle,Findbugs等等代码规则检测工具规范代码编写。 潜在的缺陷 sonar可以通过PMD,CheckStyle,Findbugs等等代码规则检测工具检 测出潜在的缺陷。 糟糕的复杂度分布 文件、类、方法等,如果复杂度过高将难以改变,这会使得开发人员 难以理解它们, 且如果没有自动化的单元测试,对于程 序中的任何组件的改变都将可能导致需要全面的回归测试。 重复 显然程序中包含大量复制粘贴的代码是质量低下的,sonar可以展示 源码中重复严重的地方。 注释不足或者过多 没有注释将使代码可读性变差,特别是当不可避免地出现人员变动 时,程序的可读性将大幅下降 而过多的注释又会使得开发人员将精力过多地花费在阅读注释上,亦违背初衷。 缺乏单元测试 sonar可以很方便地统计并展示单元测试覆盖率。 糟糕的设计

The “Why” behind PMD's rules

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 07:58:53
Is there a good resource which describes the "why" behind PMD rule sets? PMD's site has the "what" - what each rule does - but it doesn't describe why PMD has that rule and why ignoring that rule can get you in trouble in the real world. In particular, I'm interested in knowing why PMD has the AvoidInstantiatingObjectsInLoops and OnlyOneReturn rules (the first seems necessary if you need to create a new object corresponding to each object in a collection, the second seems like it is a necessity in many cases that return a value based on some criteria), but what I'm really after is a link

Unsupported @SuppressWarnings(“PMD.DoNotCallSystemExit”)

谁都会走 提交于 2019-11-30 07:49:27
I need to use System.exit(0) in an application. Eclipse has the PMD plugin installed and complains about this line of code. Adding @SuppressWarnings ("PMD.DoNotCallSystemExit") remove that warning but now I get a warning that this SuppressWarnings is unsupported, despite the fact that it works. Is there a way to resolve this? user342495 To get Eclipse to not flag the @SuppressWarnings("PMD") annotation, look under the menu headings Java -> Compiler -> Errors/Warnings -> Annotations -> Unhandled Token in '@SuppressWarnings' and set it to ignore. Right on the PMD page. 来源: https://stackoverflow

PMD - NPath complexity very high with ternary operator (?

拟墨画扇 提交于 2019-11-30 01:16:23
问题 I'm using PMD to generate some code quality report on a project. I don't understand a result for the NPath complexity inspection. I have created a dull class that is show-casing the result (this is not the real class, but it is using the same pattern): import java.util.*; public class SOFExample { private final Map<String, Date> magicMap = new HashMap<String, Date>(); protected static final long UNKNWOWN = 0L; private static final class MyCal { long aTime; long bTime; long cTime; long dTime;}

Unable to locate Source XRef to link to

白昼怎懂夜的黑 提交于 2019-11-29 22:47:21
I have a big maven project that uses the pmd plugin for code quality checks. since I started using the pmd plugin i get the following warning message: [WARNING] Unable to locate Source XRef to link to - DISABLED I googled and found that i need to implement the jxr plugin. so I add the following to the build property in the main pom.xml file. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jxr-plugin</artifactId> <version>2.3</version> </plugin> welp it doesn't really change anything. any ideas what I need to implement in order to resolve this warning message? output of