Java代码检测工具PMD规则集解决方案合集
Basic Rules : The Basic Rulet contains a collection of good practices which everyone should follow.
∙ Braces Rules : The Braces Rulet contains a collection of braces rules.
∙ Clone Implementation Rules : The Clone Implementation rulet contains a collection of rules that find questionable usages of the clone() method.
∙ inflationCode Size Rules : The Code Size Rulet contains a collection of rules that find code size related problems.
∙ Controversial Rules : The Controversial Rulet contains rules that, for whatever reason, are considered controversial. They are parated out here to allow people to include as they e fit via custom rulets. This rulet was initially created in respon to discussions over UnnecessaryConstructorRule which Tom likes but most people really dislike :-)
∙ Coupling Rules : The are rules which find instances of high or inappropriate coupling between objects and packages.
races
∙ Design Rules : The Design Rulet contains a collection of rules that find questionable designs.
∙ Finalizer Rules : The rules deal with different problems that can occur with finalizers.
∙ Import Statement Rules : The rules deal with different problems that can occur with a class' import statements.
∙ J2EE Rules : The are rules for J2EE
stepmother∙ JavaBean Rules : The JavaBeans Rulet catches instances of bean rules not being followed.
∙ JUnit Rules : The rules deal with different problems that can occur with JUnit tests.
∙ Jakarta Commons Logging Rules : The Jakarta Commons Logging rulet contains a co
llection of rules that find questionable usages of that framework.
∙ Java Logging Rules : The Java Logging rulet contains a collection of rules that find questionable usages of the logger.
∙ Migration Rules : Contains rules about migrating from one JDK version to another. Don't u the rules directly, rather, u a wrapper rulet such as migrating_l.
∙ Naming Rules : The Naming Rulet contains a collection of rules about names - too long, too short, and so forth.
∙ Optimization Rules : The rules deal with different optimizations that generally apply to performance best practices.
∙ Strict Exception Rules : The rules provide some strict guidelines about throwing and catching exceptions.
∙ String and StringBuffer Rules : The rules deal with different problems that can occur with manipulation of the class String or StringBuffer.
arcade∙ Security Code Guidelines : The rules check the curity guidelines from Sun, published at /curity/ccodeguide.html#gcg
∙ Type Resolution Rules : The are rules which resolve java Class files for comparisson, as oppod to a String
∙ Unud Code Rules : The Unud Code Rulet contains a collection of rules that find unud code.
乌拉俄语翻译∙ PMD规则之Basic Rules
∙ EmptyCatchBlock: Empty Catch Block finds instances where an exception is caught, but nothing is done. In most circumstances, this swallows an exception which should either be acted on or reported.
解决方案 空的 catch 块:发现空的 catch 块没做任何异常处理的事,在大多数情形下,这会吞噬一些应该被处理或报告的异常
∙ EmptyIfStmt: Empty If Statement finds instances where a condition is checked but nothing is done about it.
解决方案 空的 if 表达式:发现使用 if 进行了条件判断,但是判断之后没做任何处理
∙ EmptyWhileStmt: Empty While Statement finds all instances where a while statement does nothing. If it is a timing loop, then you should u Thread.sleep() for it; if it's a while loop that does a lot in the exit expression, rewrite it to make it clearer.
解决方案 空的 while 表达式:发现空的 while 表达式,如果是一个定时的循环,你应该在循环体内使用 Thread.sleep() ;如果是对于退出处理做的一个处理大量事情的 while 循环,重写代码使它更清晰
∙哈密瓜英文 EmptyTryBlock: Avoid empty try blocks - what's the point?
解决方案 空的 try apart块:避免空的 try 块
∙ EmptyFinallyBlock: Avoid empty finally blocks - the can be deleted.
解决方案 空的 韩语学习方法finally 块:避免空的 finally 块 - 这些是可以删掉的
∙ EmptySwitchStatements: Avoid empty switch statements.
解决方案 空的 switch 表达式:避免空的 英语课件网switch 表达式
∙ JumbledIncrementer: Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended.
解决方案 避免混乱的循环 增量 - 它常常是一个错误,而且容易让人迷惑
错误代码示例:
public class JumbledIncrementerRule1 {
public void foo() {
for (int i = 0; i < 10; i++) {
for (int k = 0; k < 20; i++) {
System.out.println("Hello");
} avec
}
}
}
父子循环都用i++
∙ ForLoopShouldBeWhileLoop: Some for loops can be simplified to while loops - this makes them more conci.