forked from phoedos/pmd
[doc] Update generated ruleset documentation
This commit is contained in:
@ -5,13 +5,13 @@ folder: pmd/rules
|
||||
---
|
||||
List of rulesets and rules contained in each ruleset.
|
||||
|
||||
* [Best Practices](pmd_rules_java_bestpractices.html): The Best Practices category contains rules... It fully contains these previous rulesets: * sunsecure * unusedcode
|
||||
* [Code Style](pmd_rules_java_codestyle.html): The Code Style category contains rules that enforce conventions like braces, naming, ... It fully contains these previous rulesets: * braces
|
||||
* [Design](pmd_rules_java_design.html): The Design category contains rules that flag suboptimal code implementations. Alternate approaches are suggested. It fully contains these previous rulesets: * codesize
|
||||
* [Documentation](pmd_rules_java_documentation.html): The Documentation category contains rules that deal with comments and code documentation.
|
||||
* [Error Prone](pmd_rules_java_errorprone.html): The Error Prone category contains rules, that detect incorrect usages, missed checks, ... It fully contains these previous rulesets: * android * clone * empty * finalizers * javabeans
|
||||
* [Multithreading](pmd_rules_java_multithreading.html): The Multithreading category contains rules that deal with programming errors in multi-threaded environments.
|
||||
* [Performance](pmd_rules_java_performance.html): The Performance category contains rules that deal with optimizations and performance issues.
|
||||
* [Best Practices](pmd_rules_java_bestpractices.html): Rules which enforce generally accepted best practices.
|
||||
* [Code Style](pmd_rules_java_codestyle.html): Rules which enforce a specific coding style.
|
||||
* [Design](pmd_rules_java_design.html): Rules that help you discover design issues.
|
||||
* [Documentation](pmd_rules_java_documentation.html): Rules that are related to code documentation.
|
||||
* [Error Prone](pmd_rules_java_errorprone.html): Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
|
||||
* [Multithreading](pmd_rules_java_multithreading.html): Rules that flag issues when dealing with multiple threads of execution.
|
||||
* [Performance](pmd_rules_java_performance.html): Rules that flag suboptimal code.
|
||||
|
||||
## Best Practices
|
||||
* [AbstractClassWithoutAbstractMethod](pmd_rules_java_bestpractices.html#abstractclasswithoutabstractmethod): The abstract class does not contain any abstract methods. An abstract class suggestsan incomplete...
|
||||
|
@ -1,124 +0,0 @@
|
||||
---
|
||||
title: Android
|
||||
summary: These rules deal with the Android SDK, mostly related to best practices. To get better results, make sure that the auxclasspath is defined for type resolution to work.
|
||||
permalink: pmd_rules_java_android.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
editmepath: ../pmd-java/src/main/resources/rulesets/java/android.xml
|
||||
keywords: Android, CallSuperFirst, CallSuperLast, DoNotHardCodeSDCard
|
||||
---
|
||||
## CallSuperFirst
|
||||
|
||||
**Since:** PMD 4.2.5
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Super should be called at the start of the method
|
||||
|
||||
```
|
||||
//MethodDeclaration[MethodDeclarator[
|
||||
@Image='onCreate' or
|
||||
@Image='onConfigurationChanged' or
|
||||
@Image='onPostCreate' or
|
||||
@Image='onPostResume' or
|
||||
@Image='onRestart' or
|
||||
@Image='onRestoreInstanceState' or
|
||||
@Image='onResume' or
|
||||
@Image='onStart'
|
||||
]]
|
||||
/Block[not(
|
||||
(BlockStatement[1]/Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image]))]
|
||||
[ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[
|
||||
typeof(@Image, 'android.app.Activity', 'Activity') or
|
||||
typeof(@Image, 'android.app.Application', 'Application') or
|
||||
typeof(@Image, 'android.app.Service', 'Service')
|
||||
]]]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class DummyActivity extends Activity {
|
||||
public void onCreate(Bundle bundle) {
|
||||
// missing call to super.onCreate(bundle)
|
||||
foo();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/android.xml/CallSuperFirst" />
|
||||
```
|
||||
|
||||
## CallSuperLast
|
||||
|
||||
**Since:** PMD 4.2.5
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Super should be called at the end of the method
|
||||
|
||||
```
|
||||
//MethodDeclaration[MethodDeclarator[
|
||||
@Image='finish' or
|
||||
@Image='onDestroy' or
|
||||
@Image='onPause' or
|
||||
@Image='onSaveInstanceState' or
|
||||
@Image='onStop' or
|
||||
@Image='onTerminate'
|
||||
]]
|
||||
/Block/BlockStatement[last()]
|
||||
[not(Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image])]
|
||||
[ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[
|
||||
typeof(@Image, 'android.app.Activity', 'Activity') or
|
||||
typeof(@Image, 'android.app.Application', 'Application') or
|
||||
typeof(@Image, 'android.app.Service', 'Service')
|
||||
]]]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class DummyActivity extends Activity {
|
||||
public void onPause() {
|
||||
foo();
|
||||
// missing call to super.onPause()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/android.xml/CallSuperLast" />
|
||||
```
|
||||
|
||||
## DoNotHardCodeSDCard
|
||||
|
||||
**Since:** PMD 4.2.6
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Use Environment.getExternalStorageDirectory() instead of "/sdcard"
|
||||
|
||||
```
|
||||
//Literal[starts-with(@Image,'"/sdcard')]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class MyActivity extends Activity {
|
||||
protected void foo() {
|
||||
String storageLocation = "/sdcard/mypackage"; // hard-coded, poor approach
|
||||
|
||||
storageLocation = Environment.getExternalStorageDirectory() + "/mypackage"; // preferred approach
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/android.xml/DoNotHardCodeSDCard" />
|
||||
```
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Best Practices
|
||||
summary: The Best Practices category contains rules... It fully contains these previous rulesets: * sunsecure * unusedcode
|
||||
summary: Rules which enforce generally accepted best practices.
|
||||
permalink: pmd_rules_java_bestpractices.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
@ -54,7 +54,7 @@ situation. The generated class file is actually an interface. It gives the acce
|
||||
to invoke a new hidden package scope constructor that takes the interface as a supplementary parameter.
|
||||
This turns a private constructor effectively into one with package scope, and is challenging to discern.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.AccessorClassGenerationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/AccessorClassGenerationRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.AccessorClassGenerationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AccessorClassGenerationRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -84,7 +84,7 @@ When accessing a private field / method from another class, the Java compiler wi
|
||||
with package-private visibility. This adds overhead, and to the dex method count on Android. This situation can
|
||||
be avoided by changing the visibility of the field / method from private to package-private.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.AccessorMethodGenerationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/AccessorMethodGenerationRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.AccessorMethodGenerationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AccessorMethodGenerationRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -119,7 +119,7 @@ public class OuterClass {
|
||||
Constructors and methods receiving arrays should clone objects and store the copy.
|
||||
This prevents future changes from the user from affecting the original array.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.sunsecure.ArrayIsStoredDirectlyRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/sunsecure/ArrayIsStoredDirectlyRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.ArrayIsStoredDirectlyRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ArrayIsStoredDirectlyRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -179,7 +179,7 @@ class Foo {
|
||||
|
||||
Reassigning values to incoming parameters is not recommended. Use temporary local variables instead.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.AvoidReassigningParametersRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/AvoidReassigningParametersRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.AvoidReassigningParametersRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidReassigningParametersRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -231,7 +231,7 @@ public class Foo {
|
||||
Application with hard-coded IP addresses can become impossible to deploy in some cases.
|
||||
Externalizing IP adresses is preferable.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.basic.AvoidUsingHardCodedIPRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/AvoidUsingHardCodedIPRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.AvoidUsingHardCodedIPRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidUsingHardCodedIPRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -262,7 +262,7 @@ public class Foo {
|
||||
Always check the return values of navigation methods (next, previous, first, last) of a ResultSet.
|
||||
If the value return is 'false', it should be handled properly.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.basic.CheckResultSetRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/CheckResultSetRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.CheckResultSetRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/CheckResultSetRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -384,7 +384,7 @@ lists, arrays and iterators. A loop is safe to replace if it only uses the index
|
||||
access an element of the list or array, only has one update statement, and loops through *every*
|
||||
element of the list or array left to right.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.migrating.ForLoopCanBeForeachRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/migrating/ForLoopCanBeForeachRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.ForLoopCanBeForeachRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ForLoopCanBeForeachRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -416,7 +416,7 @@ public class MyClass {
|
||||
When log messages are composed by concatenating strings, the whole section should be guarded
|
||||
by a isDebugEnabled() check to avoid performance and memory issues.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.logging.GuardDebugLoggingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardDebugLoggingRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.GuardDebugLoggingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/GuardDebugLoggingRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -465,7 +465,7 @@ public class Test {
|
||||
Whenever using a log level, one should check if the loglevel is actually enabled, or
|
||||
otherwise skip the associate String creation and manipulation.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.logging.GuardLogStatementRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardLogStatementRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.GuardLogStatementRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/GuardLogStatementRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -496,7 +496,7 @@ otherwise skip the associate String creation and manipulation.
|
||||
Whenever using a log level, one should check if the loglevel is actually enabled, or
|
||||
otherwise skip the associate String creation and manipulation.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.logging.GuardLogStatementJavaUtilRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardLogStatementJavaUtilRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.GuardLogStatementJavaUtilRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/GuardLogStatementJavaUtilRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -669,7 +669,7 @@ public class MyTest {
|
||||
JUnit assertions should include an informative message - i.e., use the three-argument version of
|
||||
assertEquals(), not the two-argument version.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.junit.JUnitAssertionsShouldIncludeMessageRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/junit/JUnitAssertionsShouldIncludeMessageRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.JUnitAssertionsShouldIncludeMessageRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/JUnitAssertionsShouldIncludeMessageRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -742,7 +742,7 @@ public class MyTestCase extends TestCase {
|
||||
JUnit tests should include at least one assertion. This makes the tests more robust, and using assert
|
||||
with messages provide the developer a clearer idea of what the test does.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.junit.JUnitTestsShouldIncludeAssertRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/junit/JUnitTestsShouldIncludeAssertRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.JUnitTestsShouldIncludeAssertRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/JUnitTestsShouldIncludeAssertRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -770,7 +770,7 @@ public class Foo extends TestCase {
|
||||
|
||||
In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.migrating.JUnitUseExpectedRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/migrating/JUnitUseExpectedRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.JUnitUseExpectedRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/JUnitUseExpectedRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -807,7 +807,7 @@ The use of implementation types (i.e., HashSet) as object references limits your
|
||||
implementations in the future as requirements change. Whenever available, referencing objects
|
||||
by their interface types (i.e, Set) provides much more flexibility.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.coupling.LooseCouplingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/LooseCouplingRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.LooseCouplingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/LooseCouplingRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -846,7 +846,7 @@ public class Bar {
|
||||
Exposing internal arrays to the caller violates object encapsulation since elements can be
|
||||
removed or replaced outside of the object that owns it. It is safer to return a copy of the array.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.sunsecure.MethodReturnsInternalArrayRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/sunsecure/MethodReturnsInternalArrayRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.MethodReturnsInternalArrayRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/MethodReturnsInternalArrayRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -992,7 +992,7 @@ Throwing a new exception from a catch block without passing the original excepti
|
||||
new exception will cause the original stack trace to be lost making it difficult to debug
|
||||
effectively.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.PreserveStackTraceRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/PreserveStackTraceRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.PreserveStackTraceRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/PreserveStackTraceRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1184,7 +1184,7 @@ class Foo{
|
||||
|
||||
Avoid passing parameters to methods or constructors without actually referencing them in the method body.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.unusedcode.UnusedFormalParameterRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/unusedcode/UnusedFormalParameterRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedFormalParameterRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedFormalParameterRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1216,7 +1216,7 @@ public class Foo {
|
||||
Avoid unused import statements to prevent unwanted dependencies.
|
||||
This rule will also find unused on demand imports, i.e. import com.foo.*.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.imports.UnusedImportsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/imports/UnusedImportsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedImportsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedImportsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1240,7 +1240,7 @@ public class Foo {}
|
||||
|
||||
Detects when a local variable is declared and/or assigned, but not used.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.unusedcode.UnusedLocalVariableRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/unusedcode/UnusedLocalVariableRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedLocalVariableRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedLocalVariableRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1265,7 +1265,7 @@ public class Foo {
|
||||
|
||||
Detects when a private field is declared and/or assigned a value, but not used.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.unusedcode.UnusedPrivateFieldRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/unusedcode/UnusedPrivateFieldRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedPrivateFieldRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedPrivateFieldRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1293,7 +1293,7 @@ public class Something {
|
||||
|
||||
Unused Private Method detects when a private method is declared but is unused.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.unusedcode.UnusedPrivateMethodRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/unusedcode/UnusedPrivateMethodRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedPrivateMethodRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedPrivateMethodRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1471,7 +1471,7 @@ public class MyTestCase extends TestCase {
|
||||
The isEmpty() method on java.util.Collection is provided to determine if a collection has any elements.
|
||||
Comparing the value of size() to 0 does not convey intent as well as the isEmpty() method.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.UseCollectionIsEmptyRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/UseCollectionIsEmptyRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.UseCollectionIsEmptyRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
|
@ -1,130 +0,0 @@
|
||||
---
|
||||
title: Braces
|
||||
summary: The Braces ruleset contains rules regarding the use and placement of braces.
|
||||
permalink: pmd_rules_java_braces.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
editmepath: ../pmd-java/src/main/resources/rulesets/java/braces.xml
|
||||
keywords: Braces, IfStmtsMustUseBraces, WhileLoopsMustUseBraces, IfElseStmtsMustUseBraces, ForLoopsMustUseBraces
|
||||
---
|
||||
## ForLoopsMustUseBraces
|
||||
|
||||
**Since:** PMD 0.7
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Avoid using 'for' statements without using curly braces. If the code formatting or
|
||||
indentation is lost then it becomes difficult to separate the code being controlled
|
||||
from the rest.
|
||||
|
||||
```
|
||||
//ForStatement[not(Statement/Block)]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
for (int i = 0; i < 42; i++)
|
||||
foo();
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/braces.xml/ForLoopsMustUseBraces" />
|
||||
```
|
||||
|
||||
## IfElseStmtsMustUseBraces
|
||||
|
||||
**Since:** PMD 0.2
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Avoid using if..else statements without using surrounding braces. If the code formatting
|
||||
or indentation is lost then it becomes difficult to separate the code being controlled
|
||||
from the rest.
|
||||
|
||||
```
|
||||
//Statement
|
||||
[parent::IfStatement[@Else='true']]
|
||||
[not(child::Block)]
|
||||
[not(child::IfStatement)]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
// this is OK
|
||||
if (foo) x++;
|
||||
|
||||
// but this is not
|
||||
if (foo)
|
||||
x = x+1;
|
||||
else
|
||||
x = x-1;
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/braces.xml/IfElseStmtsMustUseBraces" />
|
||||
```
|
||||
|
||||
## IfStmtsMustUseBraces
|
||||
|
||||
**Since:** PMD 1.0
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Avoid using if statements without using braces to surround the code block. If the code
|
||||
formatting or indentation is lost then it becomes difficult to separate the code being
|
||||
controlled from the rest.
|
||||
|
||||
```
|
||||
//IfStatement[count(*) < 3][not(Statement/Block)]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
if (foo) // not recommended
|
||||
x++;
|
||||
|
||||
if (foo) { // preferred approach
|
||||
x++;
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/braces.xml/IfStmtsMustUseBraces" />
|
||||
```
|
||||
|
||||
## WhileLoopsMustUseBraces
|
||||
|
||||
**Since:** PMD 0.7
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Avoid using 'while' statements without using braces to surround the code block. If the code
|
||||
formatting or indentation is lost then it becomes difficult to separate the code being
|
||||
controlled from the rest.
|
||||
|
||||
```
|
||||
//WhileStatement[not(Statement/Block)]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
while (true) // not recommended
|
||||
x++;
|
||||
|
||||
while (true) { // preferred approach
|
||||
x++;
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/braces.xml/WhileLoopsMustUseBraces" />
|
||||
```
|
||||
|
@ -1,193 +0,0 @@
|
||||
---
|
||||
title: Clone Implementation
|
||||
summary: The Clone Implementation ruleset contains a collection of rules that find questionable usages of the clone() method.
|
||||
permalink: pmd_rules_java_clone.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
editmepath: ../pmd-java/src/main/resources/rulesets/java/clone.xml
|
||||
keywords: Clone Implementation, ProperCloneImplementation, CloneThrowsCloneNotSupportedException, CloneMethodMustImplementCloneable, CloneMethodReturnTypeMustMatchClassName, CloneMethodMustBePublic
|
||||
---
|
||||
## CloneMethodMustBePublic
|
||||
|
||||
**Since:** PMD 5.4.0
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
The java Manual says "By convention, classes that implement this interface should override
|
||||
Object.clone (which is protected) with a public method."
|
||||
|
||||
```
|
||||
//MethodDeclaration[@Public='false']
|
||||
[MethodDeclarator/@Image = 'clone']
|
||||
[MethodDeclarator/FormalParameters/@ParameterCount = 0]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Foo implements Cloneable {
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException { // Violation, must be public
|
||||
}
|
||||
}
|
||||
|
||||
public class Foo implements Cloneable {
|
||||
@Override
|
||||
protected Foo clone() { // Violation, must be public
|
||||
}
|
||||
}
|
||||
|
||||
public class Foo implements Cloneable {
|
||||
@Override
|
||||
public Object clone() // Ok
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/clone.xml/CloneMethodMustBePublic" />
|
||||
```
|
||||
|
||||
## CloneMethodMustImplementCloneable
|
||||
|
||||
**Since:** PMD 1.9
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
The method clone() should only be implemented if the class implements the Cloneable interface with the exception of
|
||||
a final method that only throws CloneNotSupportedException.
|
||||
|
||||
The rule can also detect, if the class implements or extends a Cloneable class.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.clone.CloneMethodMustImplementCloneableRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/clone/CloneMethodMustImplementCloneableRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class MyClass {
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
return foo;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/clone.xml/CloneMethodMustImplementCloneable" />
|
||||
```
|
||||
|
||||
## CloneMethodReturnTypeMustMatchClassName
|
||||
|
||||
**Since:** PMD 5.4.0
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
**Minimum Language Version:** Java 1.5
|
||||
|
||||
If a class implements cloneable the return type of the method clone() must be the class name. That way, the caller
|
||||
of the clone method doesn't need to cast the returned clone to the correct type.
|
||||
|
||||
Note: This is only possible with Java 1.5 or higher.
|
||||
|
||||
```
|
||||
//MethodDeclaration
|
||||
[
|
||||
MethodDeclarator/@Image = 'clone'
|
||||
and MethodDeclarator/FormalParameters/@ParameterCount = 0
|
||||
and not (ResultType//ClassOrInterfaceType/@Image = ancestor::ClassOrInterfaceDeclaration[1]/@Image)
|
||||
]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Foo implements Cloneable {
|
||||
@Override
|
||||
protected Object clone() { // Violation, Object must be Foo
|
||||
}
|
||||
}
|
||||
|
||||
public class Foo implements Cloneable {
|
||||
@Override
|
||||
public Foo clone() { //Ok
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/clone.xml/CloneMethodReturnTypeMustMatchClassName" />
|
||||
```
|
||||
|
||||
## CloneThrowsCloneNotSupportedException
|
||||
|
||||
**Since:** PMD 1.9
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
The method clone() should throw a CloneNotSupportedException.
|
||||
|
||||
```
|
||||
//MethodDeclaration
|
||||
[
|
||||
MethodDeclarator/@Image = 'clone'
|
||||
and count(MethodDeclarator/FormalParameters/*) = 0
|
||||
and count(NameList/Name[contains
|
||||
(@Image,'CloneNotSupportedException')]) = 0
|
||||
]
|
||||
[
|
||||
../../../../ClassOrInterfaceDeclaration[@Final = 'false']
|
||||
]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class MyClass implements Cloneable{
|
||||
public Object clone() { // will cause an error
|
||||
MyClass clone = (MyClass)super.clone();
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/clone.xml/CloneThrowsCloneNotSupportedException" />
|
||||
```
|
||||
|
||||
## ProperCloneImplementation
|
||||
|
||||
**Since:** PMD 1.4
|
||||
|
||||
**Priority:** Medium High (2)
|
||||
|
||||
Object clone() should be implemented with super.clone().
|
||||
|
||||
```
|
||||
//MethodDeclarator
|
||||
[@Image = 'clone']
|
||||
[count(FormalParameters/*) = 0]
|
||||
[count(../Block//*[
|
||||
(self::AllocationExpression) and
|
||||
(./ClassOrInterfaceType/@Image = ancestor::
|
||||
ClassOrInterfaceDeclaration[1]/@Image)
|
||||
])> 0
|
||||
]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
class Foo{
|
||||
public Object clone(){
|
||||
return new Foo(); // This is bad
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/clone.xml/ProperCloneImplementation" />
|
||||
```
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Code Style
|
||||
summary: The Code Style category contains rules that enforce conventions like braces, naming, ... It fully contains these previous rulesets: * braces
|
||||
summary: Rules which enforce a specific coding style.
|
||||
permalink: pmd_rules_java_codestyle.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
@ -86,7 +86,7 @@ public class Foo {
|
||||
|
||||
Avoid using dollar signs in variable/method/class/interface names.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.naming.AvoidDollarSignsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/naming/AvoidDollarSignsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.AvoidDollarSignsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/AvoidDollarSignsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -367,7 +367,7 @@ public class Foo extends Bar{
|
||||
|
||||
Class names should always begin with an upper case character.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.naming.ClassNamingConventionsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/naming/ClassNamingConventionsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.ClassNamingConventionsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/ClassNamingConventionsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -390,7 +390,7 @@ To avoid mistakes if we want that a Method, Constructor, Field or Nested class h
|
||||
we must add a comment at the beginning of it's declaration.
|
||||
By default the comment must be /* default */, if you want another, you have to provide a regexp.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.comments.CommentDefaultAccessModifierRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentDefaultAccessModifierRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.CommentDefaultAccessModifierRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/CommentDefaultAccessModifierRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -441,7 +441,7 @@ Most "if (x != y)" cases without an "else" are often return cases, so consistent
|
||||
rule makes the code easier to read. Also, this resolves trivial ordering problems, such
|
||||
as "does the error case go first?" or "does the common case go first?".
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.ConfusingTernaryRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ConfusingTernaryRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.ConfusingTernaryRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/ConfusingTernaryRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -495,7 +495,7 @@ or MethodDeclaration[@PackagePrivate='true']
|
||||
|
||||
Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3).
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.imports.DontImportJavaLangRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/imports/DontImportJavaLangRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.DontImportJavaLangRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/DontImportJavaLangRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -524,7 +524,7 @@ public class Foo {}
|
||||
|
||||
Duplicate or overlapping import statements should be avoided.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.imports.DuplicateImportsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/imports/DuplicateImportsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.DuplicateImportsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/DuplicateImportsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -617,7 +617,7 @@ public class Foo extends Object { // not required
|
||||
|
||||
Fields should be declared at the top of the class, before any method declarations, constructors, initializers or inner classes.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.FieldDeclarationsShouldBeAtStartOfClassRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/FieldDeclarationsShouldBeAtStartOfClassRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.FieldDeclarationsShouldBeAtStartOfClassRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/FieldDeclarationsShouldBeAtStartOfClassRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -891,7 +891,7 @@ public interface MissingProperSuffix extends javax.ejb.EJBLocalObject {} // n
|
||||
|
||||
A local variable assigned only once can be declared final.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.optimizations.LocalVariableCouldBeFinalRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/LocalVariableCouldBeFinalRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.LocalVariableCouldBeFinalRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/LocalVariableCouldBeFinalRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -991,7 +991,7 @@ public class MissingTheProperSuffix implements SessionBean {} // non-standard
|
||||
|
||||
A method argument that is never re-assigned within the method can be declared final.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.optimizations.MethodArgumentCouldBeFinalRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/MethodArgumentCouldBeFinalRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.MethodArgumentCouldBeFinalRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/MethodArgumentCouldBeFinalRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1018,7 +1018,7 @@ public void foo2 (final String param) { // better, do stuff with param never ass
|
||||
|
||||
Method names should always begin with a lower case character, and should not contain underscores.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.naming.MethodNamingConventionsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/naming/MethodNamingConventionsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.MethodNamingConventionsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/MethodNamingConventionsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1103,7 +1103,7 @@ public class ClassInDefaultPackage {
|
||||
|
||||
A method should have only one exit point, and that should be the last statement in the method.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.controversial.OnlyOneReturnRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/controversial/OnlyOneReturnRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.OnlyOneReturnRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/OnlyOneReturnRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1157,7 +1157,7 @@ public class SomeClass {
|
||||
|
||||
Checks for variables that are defined before they might be used. A reference is deemed to be premature if it is created right before a block of code that doesn't use it that also has the ability to return or throw an exception.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.optimizations.PrematureDeclarationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/PrematureDeclarationRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.PrematureDeclarationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/PrematureDeclarationRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1509,7 +1509,7 @@ public final class Foo {
|
||||
Import statements allow the use of non-fully qualified names. The use of a fully qualified name
|
||||
which is covered by an import statement is redundant. Consider using the non-fully qualified name.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.imports.UnnecessaryFullyQualifiedNameRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/imports/UnnecessaryFullyQualifiedNameRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.UnnecessaryFullyQualifiedNameRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryFullyQualifiedNameRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1535,7 +1535,7 @@ public class Foo {
|
||||
|
||||
Avoid the creation of unnecessary local variables
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.UnnecessaryLocalBeforeReturnRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/UnnecessaryLocalBeforeReturnRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.UnnecessaryLocalBeforeReturnRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryLocalBeforeReturnRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1571,7 +1571,7 @@ Classes, interfaces or annotations nested in an interface or annotation are auto
|
||||
Nested enums are automatically `static`.
|
||||
For historical reasons, modifiers which are implied by the context are accepted by the compiler, but are superfluous.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.unnecessary.UnnecessaryModifierRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UnnecessaryModifierRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.UnnecessaryModifierRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryModifierRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1609,7 +1609,7 @@ public class Bar {
|
||||
|
||||
Avoid the use of unnecessary return statements.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.unnecessary.UnnecessaryReturnRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UnnecessaryReturnRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.UnnecessaryReturnRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryReturnRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1772,7 +1772,7 @@ A variable naming conventions rule - customize this to your liking. Currently,
|
||||
checks for final variables that should be fully capitalized and non-final variables
|
||||
that should not include underscores.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.naming.VariableNamingConventionsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/naming/VariableNamingConventionsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codestyle.VariableNamingConventionsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/VariableNamingConventionsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
|
@ -1,165 +0,0 @@
|
||||
---
|
||||
title: Comments
|
||||
summary: Rules intended to catch errors related to code comments
|
||||
permalink: pmd_rules_java_comments.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
editmepath: ../pmd-java/src/main/resources/rulesets/java/comments.xml
|
||||
keywords: Comments, CommentRequired, CommentSize, CommentContent, CommentDefaultAccessModifier
|
||||
---
|
||||
## CommentContent
|
||||
|
||||
**Since:** PMD 5.0
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
A rule for the politically correct... we don't want to offend anyone.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.comments.CommentContentRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentContentRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
//OMG, this is horrible, Bob is an idiot !!!
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|disallowedTerms|[idiot, jerk]|Illegal terms or phrases|
|
||||
|caseSensitive|false|Case sensitive|
|
||||
|wordsAreRegex|false|Use regular expressions|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/comments.xml/CommentContent" />
|
||||
```
|
||||
|
||||
## CommentDefaultAccessModifier
|
||||
|
||||
**Since:** PMD 5.4.0
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
To avoid mistakes if we want that a Method, Constructor, Field or Nested class have a default access modifier
|
||||
we must add a comment at the beginning of it's declaration.
|
||||
By default the comment must be /* default */, if you want another, you have to provide a regexp.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.comments.CommentDefaultAccessModifierRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentDefaultAccessModifierRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Foo {
|
||||
final String stringValue = "some string";
|
||||
String getString() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
class NestedFoo {
|
||||
}
|
||||
}
|
||||
|
||||
// should be
|
||||
public class Foo {
|
||||
/* default */ final String stringValue = "some string";
|
||||
/* default */ String getString() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
/* default */ class NestedFoo {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|regex||Regular expression|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/comments.xml/CommentDefaultAccessModifier" />
|
||||
```
|
||||
|
||||
## CommentRequired
|
||||
|
||||
**Since:** PMD 5.1
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Denotes whether comments are required (or unwanted) for specific language elements.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.comments.CommentRequiredRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentRequiredRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Jon Doe
|
||||
*/
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|serialVersionUIDCommentRequired|Ignored|serial version UID commts. Possible values: [Required, Ignored, Unwanted]|
|
||||
|enumCommentRequirement|Required|Enum comments. Possible values: [Required, Ignored, Unwanted]|
|
||||
|protectedMethodCommentRequirement|Required|Protected method constructor comments. Possible values: [Required, Ignored, Unwanted]|
|
||||
|publicMethodCommentRequirement|Required|Public method and constructor comments. Possible values: [Required, Ignored, Unwanted]|
|
||||
|fieldCommentRequirement|Required|Field comments. Possible values: [Required, Ignored, Unwanted]|
|
||||
|headerCommentRequirement|Required|Header comments. Possible values: [Required, Ignored, Unwanted]|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/comments.xml/CommentRequired" />
|
||||
```
|
||||
|
||||
## CommentSize
|
||||
|
||||
**Since:** PMD 5.0
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Determines whether the dimensions of non-header comments found are within the specified limits.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.comments.CommentSizeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentSizeRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
/**
|
||||
*
|
||||
* too many lines!
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|maxLines|6|Maximum lines|
|
||||
|maxLineLength|80|Maximum line length|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/comments.xml/CommentSize" />
|
||||
```
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,212 +0,0 @@
|
||||
---
|
||||
title: Coupling
|
||||
summary: Rules which find instances of high or inappropriate coupling between objects and packages.
|
||||
permalink: pmd_rules_java_coupling.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
editmepath: ../pmd-java/src/main/resources/rulesets/java/coupling.xml
|
||||
keywords: Coupling, CouplingBetweenObjects, ExcessiveImports, LooseCoupling, LoosePackageCoupling, LawOfDemeter
|
||||
---
|
||||
## CouplingBetweenObjects
|
||||
|
||||
**Since:** PMD 1.04
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
This rule counts the number of unique attributes, local variables, and return types within an object.
|
||||
A number higher than the specified threshold can indicate a high degree of coupling.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.coupling.CouplingBetweenObjectsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/CouplingBetweenObjectsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
import com.Blah;
|
||||
import org.Bar;
|
||||
import org.Bardo;
|
||||
|
||||
public class Foo {
|
||||
private Blah var1;
|
||||
private Bar var2;
|
||||
|
||||
//followed by many imports of unique objects
|
||||
void ObjectC doWork() {
|
||||
Bardo var55;
|
||||
ObjectA var44;
|
||||
ObjectZ var93;
|
||||
return something;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|threshold|20|Unique type reporting threshold|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/coupling.xml/CouplingBetweenObjects" />
|
||||
```
|
||||
|
||||
## ExcessiveImports
|
||||
|
||||
**Since:** PMD 1.04
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
A high number of imports can indicate a high degree of coupling within an object. This rule
|
||||
counts the number of unique imports and reports a violation if the count is above the
|
||||
user-specified threshold.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.coupling.ExcessiveImportsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/ExcessiveImportsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
import blah.blah.Baz;
|
||||
import blah.blah.Bif;
|
||||
// 18 others from the same package elided
|
||||
public class Foo {
|
||||
public void doWork() {}
|
||||
}
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|topscore||Top score value|
|
||||
|minimum||Minimum reporting threshold|
|
||||
|sigma||Sigma value|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/coupling.xml/ExcessiveImports" />
|
||||
```
|
||||
|
||||
## LawOfDemeter
|
||||
|
||||
**Since:** PMD 5.0
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
The Law of Demeter is a simple rule, that says "only talk to friends". It helps to reduce coupling between classes
|
||||
or objects.
|
||||
|
||||
See also the references:
|
||||
|
||||
* Andrew Hunt, David Thomas, and Ward Cunningham. The Pragmatic Programmer. From Journeyman to Master. Addison-Wesley Longman, Amsterdam, October 1999.;
|
||||
* K.J. Lieberherr and I.M. Holland. Assuring good style for object-oriented programs. Software, IEEE, 6(5):38–48, 1989.;
|
||||
* <http://www.ccs.neu.edu/home/lieber/LoD.html>
|
||||
* <http://en.wikipedia.org/wiki/Law_of_Demeter>
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.coupling.LawOfDemeterRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/LawOfDemeterRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Foo {
|
||||
/**
|
||||
* This example will result in two violations.
|
||||
*/
|
||||
public void example(Bar b) {
|
||||
// this method call is ok, as b is a parameter of "example"
|
||||
C c = b.getC();
|
||||
|
||||
// this method call is a violation, as we are using c, which we got from B.
|
||||
// We should ask b directly instead, e.g. "b.doItOnC();"
|
||||
c.doIt();
|
||||
|
||||
// this is also a violation, just expressed differently as a method chain without temporary variables.
|
||||
b.getC().doIt();
|
||||
|
||||
// a constructor call, not a method call.
|
||||
D d = new D();
|
||||
// this method call is ok, because we have create the new instance of D locally.
|
||||
d.doSomethingElse();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/coupling.xml/LawOfDemeter" />
|
||||
```
|
||||
|
||||
## LooseCoupling
|
||||
|
||||
**Since:** PMD 0.7
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
The use of implementation types (i.e., HashSet) as object references limits your ability to use alternate
|
||||
implementations in the future as requirements change. Whenever available, referencing objects
|
||||
by their interface types (i.e, Set) provides much more flexibility.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.coupling.LooseCouplingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/LooseCouplingRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class Bar {
|
||||
// sub-optimal approach
|
||||
private ArrayList<SomeType> list = new ArrayList<>();
|
||||
|
||||
public HashSet<SomeType> getFoo() {
|
||||
return new HashSet<SomeType>();
|
||||
}
|
||||
|
||||
// preferred approach
|
||||
private List<SomeType> list = new ArrayList<>();
|
||||
|
||||
public Set<SomeType> getFoo() {
|
||||
return new HashSet<SomeType>();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/coupling.xml/LooseCoupling" />
|
||||
```
|
||||
|
||||
## LoosePackageCoupling
|
||||
|
||||
**Since:** PMD 5.0
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Avoid using classes from the configured package hierarchy outside of the package hierarchy,
|
||||
except when using one of the configured allowed classes.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.coupling.LoosePackageCouplingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/LoosePackageCouplingRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
package some.package;
|
||||
|
||||
import some.other.package.subpackage.subsubpackage.DontUseThisClass;
|
||||
|
||||
public class Bar {
|
||||
DontUseThisClass boo = new DontUseThisClass();
|
||||
}
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|classes|[]|Allowed classes|
|
||||
|packages|[]|Restricted packages|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/coupling.xml/LoosePackageCoupling" />
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Design
|
||||
summary: The Design category contains rules that flag suboptimal code implementations. Alternate approaches are suggested. It fully contains these previous rulesets: * codesize
|
||||
summary: Rules that help you discover design issues.
|
||||
permalink: pmd_rules_java_design.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
@ -332,7 +332,7 @@ void bar() {
|
||||
This rule counts the number of unique attributes, local variables, and return types within an object.
|
||||
A number higher than the specified threshold can indicate a high degree of coupling.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.coupling.CouplingBetweenObjectsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/CouplingBetweenObjectsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.CouplingBetweenObjectsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CouplingBetweenObjectsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -379,7 +379,7 @@ plus one for the method entry. The decision points include 'if', 'while', 'for'
|
||||
Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote moderate complexity, 8-10 denote
|
||||
high complexity, and 11+ is very high complexity.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.CyclomaticComplexityRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/CyclomaticComplexityRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.CyclomaticComplexityRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CyclomaticComplexityRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -454,7 +454,7 @@ most cases, that means moving the operations defined on the data back into the c
|
||||
In some other cases it may make sense to remove entirely the class and move the data
|
||||
into the former client classes.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.metrics.rule.DataClassRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/rule/DataClassRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.DataClassRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/DataClassRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -509,7 +509,7 @@ public class Foo extends Error { }
|
||||
Using Exceptions as form of flow control is not recommended as they obscure true exceptions when debugging.
|
||||
Either add the necessary validation or use an alternate control structure.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strictexception.ExceptionAsFlowControlRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strictexception/ExceptionAsFlowControlRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.ExceptionAsFlowControlRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ExceptionAsFlowControlRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -542,7 +542,7 @@ Excessive class file lengths are usually indications that the class may be burde
|
||||
responsibilities that could be provided by external classes or functions. In breaking these methods
|
||||
apart the code becomes more manageable and ripe for reuse.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.ExcessiveClassLengthRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/ExcessiveClassLengthRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.ExcessiveClassLengthRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ExcessiveClassLengthRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -587,7 +587,7 @@ A high number of imports can indicate a high degree of coupling within an object
|
||||
counts the number of unique imports and reports a violation if the count is above the
|
||||
user-specified threshold.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.coupling.ExcessiveImportsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/ExcessiveImportsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.ExcessiveImportsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ExcessiveImportsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -624,7 +624,7 @@ name/signature might suggest. They also become challenging for others to digest
|
||||
scrolling causes readers to lose focus.
|
||||
Try to reduce the method length by creating helper methods and removing any copy/pasted code.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.ExcessiveMethodLengthRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/ExcessiveMethodLengthRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.ExcessiveMethodLengthRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ExcessiveMethodLengthRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -658,7 +658,7 @@ public void doSomething() {
|
||||
Methods with numerous parameters are a challenge to maintain, especially if most of them share the
|
||||
same datatype. These situations usually denote the need for new objects to wrap the numerous parameters.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.ExcessiveParameterListRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/ExcessiveParameterListRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.ExcessiveParameterListRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ExcessiveParameterListRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -700,7 +700,7 @@ since combinational side effects grow rapidly and increase risk. Refactoring the
|
||||
smaller ones not only increases testability and reliability but also allows new variations to be
|
||||
developed easily.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.ExcessivePublicCountRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/ExcessivePublicCountRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.ExcessivePublicCountRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ExcessivePublicCountRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -830,7 +830,7 @@ See also the references:
|
||||
* <http://www.ccs.neu.edu/home/lieber/LoD.html>
|
||||
* <http://en.wikipedia.org/wiki/Law_of_Demeter>
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.coupling.LawOfDemeterRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/LawOfDemeterRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.LawOfDemeterRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/LawOfDemeterRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -906,7 +906,7 @@ public boolean bar(int a, int b) {
|
||||
Avoid using classes from the configured package hierarchy outside of the package hierarchy,
|
||||
except when using one of the configured allowed classes.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.coupling.LoosePackageCouplingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/LoosePackageCouplingRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.LoosePackageCouplingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/LoosePackageCouplingRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -946,7 +946,7 @@ Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote moderate c
|
||||
high complexity, and 11+ is very high complexity. Modified complexity treats switch statements as a single
|
||||
decision point.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.ModifiedCyclomaticComplexityRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/ModifiedCyclomaticComplexityRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.ModifiedCyclomaticComplexityRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ModifiedCyclomaticComplexityRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1014,7 +1014,7 @@ This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determin
|
||||
of code for a given constructor. NCSS ignores comments, and counts actual statements. Using this algorithm,
|
||||
lines of code that are split are counted as one.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.NcssConstructorCountRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/NcssConstructorCountRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.NcssConstructorCountRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NcssConstructorCountRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1057,7 +1057,7 @@ of code in a class, method or constructor. NCSS ignores comments, blank lines, a
|
||||
statements. For more details on the calculation, see the documentation of
|
||||
the [NCSS metric](/pmd_java_metrics_index.html#non-commenting-source-statements-ncss).
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.NcssCountRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/NcssCountRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.NcssCountRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NcssCountRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1114,7 +1114,7 @@ This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determin
|
||||
of code for a given method. NCSS ignores comments, and counts actual statements. Using this algorithm,
|
||||
lines of code that are split are counted as one.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.NcssMethodCountRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/NcssMethodCountRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.NcssMethodCountRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NcssMethodCountRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1159,7 +1159,7 @@ This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determin
|
||||
of code for a given type. NCSS ignores comments, and counts actual statements. Using this algorithm,
|
||||
lines of code that are split are counted as one.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.NcssTypeCountRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/NcssTypeCountRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.NcssTypeCountRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NcssTypeCountRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1201,7 +1201,7 @@ The NPath complexity of a method is the number of acyclic execution paths throug
|
||||
A threshold of 200 is generally considered the point where measures should be taken to reduce
|
||||
complexity and increase readability.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.NPathComplexityRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/NPathComplexityRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.NPathComplexityRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NPathComplexityRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1259,7 +1259,7 @@ is unclear which exceptions that can be thrown from the methods. It might be
|
||||
difficult to document and understand such vague interfaces. Use either a class
|
||||
derived from RuntimeException or a checked exception.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strictexception.SignatureDeclareThrowsExceptionRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strictexception/SignatureDeclareThrowsExceptionRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.SignatureDeclareThrowsExceptionRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SignatureDeclareThrowsExceptionRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1535,7 +1535,7 @@ plus one for the method entry. The decision points include 'if', 'while', 'for'
|
||||
Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote moderate complexity, 8-10 denote
|
||||
high complexity, and 11+ is very high complexity.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.StdCyclomaticComplexityRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/StdCyclomaticComplexityRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.StdCyclomaticComplexityRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/StdCyclomaticComplexityRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1644,7 +1644,7 @@ Classes that have too many fields can become unwieldy and could be redesigned to
|
||||
possibly through grouping related fields in new objects. For example, a class with individual
|
||||
city/state/zip fields could park them within a single Address field.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.codesize.TooManyFieldsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codesize/TooManyFieldsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.TooManyFieldsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/TooManyFieldsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1717,7 +1717,7 @@ complexity and find a way to have more fine grained objects.
|
||||
|
||||
The overriding method merely calls the same method defined in a superclass.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.unnecessary.UselessOverridingMethodRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UselessOverridingMethodRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.UselessOverridingMethodRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/UselessOverridingMethodRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Documentation
|
||||
summary: The Documentation category contains rules that deal with comments and code documentation.
|
||||
summary: Rules that are related to code documentation.
|
||||
permalink: pmd_rules_java_documentation.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
@ -15,7 +15,7 @@ keywords: Documentation, CommentContent, CommentRequired, CommentSize, Uncomment
|
||||
|
||||
A rule for the politically correct... we don't want to offend anyone.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.comments.CommentContentRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentContentRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.documentation.CommentContentRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentContentRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -44,7 +44,7 @@ A rule for the politically correct... we don't want to offend anyone.
|
||||
|
||||
Denotes whether comments are required (or unwanted) for specific language elements.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.comments.CommentRequiredRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentRequiredRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.documentation.CommentRequiredRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentRequiredRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -80,7 +80,7 @@ Denotes whether comments are required (or unwanted) for specific language elemen
|
||||
|
||||
Determines whether the dimensions of non-header comments found are within the specified limits.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.comments.CommentSizeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentSizeRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.documentation.CommentSizeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentSizeRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Error Prone
|
||||
summary: The Error Prone category contains rules, that detect incorrect usages, missed checks, ... It fully contains these previous rulesets: * android * clone * empty * finalizers * javabeans
|
||||
summary: Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
|
||||
permalink: pmd_rules_java_errorprone.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
@ -15,7 +15,7 @@ keywords: Error Prone, AssignmentInOperand, AssignmentToNonFinalStatic, AvoidAcc
|
||||
|
||||
Avoid assignments in operands; this can make code more complicated and harder to read.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.controversial.AssignmentInOperandRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/controversial/AssignmentInOperandRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.AssignmentInOperandRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AssignmentInOperandRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -50,7 +50,7 @@ public void bar() {
|
||||
|
||||
Identifies a possible unsafe usage of a static field.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.AssignmentToNonFinalStaticRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/AssignmentToNonFinalStaticRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.AssignmentToNonFinalStaticRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AssignmentToNonFinalStaticRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -176,7 +176,7 @@ public class A {
|
||||
Using a branching statement as the last part of a loop may be a bug, and/or is confusing.
|
||||
Ensure that the usage is not a bug, or consider using another approach.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.basic.AvoidBranchingStatementAsLastInLoopRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/AvoidBranchingStatementAsLastInLoopRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.AvoidBranchingStatementAsLastInLoopRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidBranchingStatementAsLastInLoopRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -219,7 +219,7 @@ for (int i = 0; i < 10; i++) {
|
||||
The method Object.finalize() is called by the garbage collector on an object when garbage collection determines
|
||||
that there are no more references to the object. It should not be invoked by application logic.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.finalizers.AvoidCallingFinalizeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/finalizers/AvoidCallingFinalizeRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.AvoidCallingFinalizeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidCallingFinalizeRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -276,7 +276,7 @@ public class Foo {
|
||||
Catching Throwable errors is not recommended since its scope is very broad. It includes runtime issues such as
|
||||
OutOfMemoryError that should be exposed and managed separately.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strictexception.AvoidCatchingThrowableRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strictexception/AvoidCatchingThrowableRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.AvoidCatchingThrowableRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidCatchingThrowableRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -356,7 +356,7 @@ BigDecimal bd = new BigDecimal(12); // preferred approach, ok for integ
|
||||
|
||||
Code containing duplicate String literals can usually be improved by declaring the String as a constant field.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.AvoidDuplicateLiteralsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/AvoidDuplicateLiteralsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.AvoidDuplicateLiteralsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidDuplicateLiteralsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -423,7 +423,7 @@ It can be confusing to have a field name with the same name as a method. While t
|
||||
having information (field) and actions (method) is not clear naming. Developers versed in
|
||||
Smalltalk often prefer this approach as the methods denote accessor methods.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.naming.AvoidFieldNameMatchingMethodNameRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/naming/AvoidFieldNameMatchingMethodNameRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.AvoidFieldNameMatchingMethodNameRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidFieldNameMatchingMethodNameRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -450,7 +450,7 @@ public class Foo {
|
||||
It is somewhat confusing to have a field name matching the declaring class name.
|
||||
This probably means that type and/or field names should be chosen more carefully.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.naming.AvoidFieldNameMatchingTypeNameRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/naming/AvoidFieldNameMatchingTypeNameRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.AvoidFieldNameMatchingTypeNameRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidFieldNameMatchingTypeNameRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -606,7 +606,7 @@ public void bar() {
|
||||
The use of multiple unary operators may be problematic, and/or confusing.
|
||||
Ensure that the intended usage is not a bug, or consider simplifying the expression.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.basic.AvoidMultipleUnaryOperatorsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/AvoidMultipleUnaryOperatorsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.AvoidMultipleUnaryOperatorsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidMultipleUnaryOperatorsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -644,7 +644,7 @@ int j = -~7;
|
||||
Integer literals should not start with zero since this denotes that the rest of literal will be
|
||||
interpreted as an octal value.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.basic.AvoidUsingOctalValuesRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/AvoidUsingOctalValuesRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.AvoidUsingOctalValuesRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidUsingOctalValuesRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -702,7 +702,7 @@ Member variables need to be marked as transient, static, or have accessor method
|
||||
variables as transient is the safest and easiest modification. Accessor methods should follow the Java
|
||||
naming conventions, i.e. for a variable named foo, getFoo() and setFoo() accessor methods should be provided.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.javabeans.BeanMembersShouldSerializeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/javabeans/BeanMembersShouldSerializeRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.BeanMembersShouldSerializeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/BeanMembersShouldSerializeRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -741,7 +741,7 @@ private int getMoreFoo(){
|
||||
The null check is broken since it will throw a NullPointerException itself.
|
||||
It is likely that you used || instead of && or vice versa.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.basic.BrokenNullCheckRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/BrokenNullCheckRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.BrokenNullCheckRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/BrokenNullCheckRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -855,7 +855,7 @@ public class DummyActivity extends Activity {
|
||||
|
||||
The skip() method may skip a smaller number of bytes than requested. Check the returned value to find out if it was the case or not.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.basic.CheckSkipResultRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/CheckSkipResultRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.CheckSkipResultRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CheckSkipResultRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -976,7 +976,7 @@ a final method that only throws CloneNotSupportedException.
|
||||
|
||||
The rule can also detect, if the class implements or extends a Cloneable class.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.clone.CloneMethodMustImplementCloneableRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/clone/CloneMethodMustImplementCloneableRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.CloneMethodMustImplementCloneableRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloneMethodMustImplementCloneableRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1081,7 +1081,7 @@ public class MyClass implements Cloneable{
|
||||
|
||||
Ensure that resources (like Connection, Statement, and ResultSet objects) are always closed after use.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.CloseResourceRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CloseResourceRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.CloseResourceRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloseResourceRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1122,7 +1122,7 @@ public class Bar {
|
||||
|
||||
Use equals() to compare object references; avoid comparing them with ==.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.CompareObjectsWithEqualsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CompareObjectsWithEqualsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.CompareObjectsWithEqualsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CompareObjectsWithEqualsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1153,7 +1153,7 @@ contains a call to an overridable method, the subclass may be completely uninsta
|
||||
this includes method calls throughout the control flow graph - i.e., if a constructor Foo() calls a
|
||||
private method bar() that calls a public method buz(), this denotes a problem.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.ConstructorCallsOverridableMethodRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ConstructorCallsOverridableMethodRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.ConstructorCallsOverridableMethodRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ConstructorCallsOverridableMethodRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1196,7 +1196,7 @@ From those informations there can be found various problems.
|
||||
2. DU - Anomaly: A recently defined variable is undefined. These anomalies may appear in normal source text.
|
||||
3. DD - Anomaly: A recently defined variable is redefined. This is ominous but don't have to be a bug.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.controversial.DataflowAnomalyAnalysisRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/controversial/DataflowAnomalyAnalysisRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.DataflowAnomalyAnalysisRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/DataflowAnomalyAnalysisRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -1405,7 +1405,7 @@ public class Foo {
|
||||
|
||||
Avoid importing anything from the 'sun.*' packages. These packages are not portable and are likely to change.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.controversial.DontImportSunRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/controversial/DontImportSunRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.DontImportSunRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/DontImportSunRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -2007,7 +2007,7 @@ public void finalize() {
|
||||
|
||||
Avoid idempotent operations - they have no effect.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.IdempotentOperationsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/IdempotentOperationsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.IdempotentOperationsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/IdempotentOperationsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -2033,7 +2033,7 @@ public class Foo {
|
||||
|
||||
There is no need to import a type that lives in the same package.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.imports.ImportFromSamePackageRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/imports/ImportFromSamePackageRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.ImportFromSamePackageRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ImportFromSamePackageRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -2091,7 +2091,7 @@ Class c = String.class;
|
||||
|
||||
Check for messages in slf4j loggers with non matching number of arguments and placeholders.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.logging.InvalidSlf4jMessageFormatRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/InvalidSlf4jMessageFormatRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.InvalidSlf4jMessageFormatRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/InvalidSlf4jMessageFormatRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -2246,7 +2246,7 @@ public class Foo{
|
||||
|
||||
Non-constructor methods should not have the same name as the enclosing class.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.naming.MethodWithSameNameAsEnclosingClassRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/naming/MethodWithSameNameAsEnclosingClassRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.MethodWithSameNameAsEnclosingClassRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/MethodWithSameNameAsEnclosingClassRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -2462,7 +2462,7 @@ public class Foo {
|
||||
|
||||
Normally only one logger is used in each class.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.logging.MoreThanOneLoggerRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/MoreThanOneLoggerRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.MoreThanOneLoggerRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/MoreThanOneLoggerRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -2557,7 +2557,7 @@ of assignment is an indication that the programmer doesn't completely understand
|
||||
|
||||
NOTE: This sort of assignment may used in some cases to dereference objects and encourage garbage collection.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.controversial.NullAssignmentRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/controversial/NullAssignmentRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.NullAssignmentRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/NullAssignmentRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -2584,7 +2584,7 @@ public void bar() {
|
||||
|
||||
Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.basic.OverrideBothEqualsAndHashcodeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/OverrideBothEqualsAndHashcodeRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.OverrideBothEqualsAndHashcodeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -2809,7 +2809,7 @@ Some classes contain overloaded getInstance. The problem with overloaded getInst
|
||||
is that the instance created using the overloaded method is not cached and so,
|
||||
for each call and new objects will be created for every invocation.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.SingleMethodSingletonRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SingleMethodSingletonRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.SingleMethodSingletonRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/SingleMethodSingletonRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -2846,7 +2846,7 @@ Some classes contain overloaded getInstance. The problem with overloaded getInst
|
||||
is that the instance created using the overloaded method is not cached and so,
|
||||
for each call and new objects will be created for every invocation.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.SingletonClassReturningNewInstanceRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SingletonClassReturningNewInstanceRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.SingletonClassReturningNewInstanceRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/SingletonClassReturningNewInstanceRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -3026,7 +3026,7 @@ public class Foo {
|
||||
The method name and return type are suspiciously close to hashCode(), which may denote an intention
|
||||
to override the hashCode() method.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.naming.SuspiciousHashcodeMethodNameRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/naming/SuspiciousHashcodeMethodNameRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.SuspiciousHashcodeMethodNameRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/SuspiciousHashcodeMethodNameRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -3059,7 +3059,7 @@ Any octal escape sequence followed by non-octal digits can be confusing,
|
||||
e.g. "\038" is interpreted as the octal escape sequence "\03" followed by
|
||||
the literal character "8".
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.controversial.SuspiciousOctalEscapeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/controversial/SuspiciousOctalEscapeRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.SuspiciousOctalEscapeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/SuspiciousOctalEscapeRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -3084,7 +3084,7 @@ public void foo() {
|
||||
Test classes end with the suffix Test. Having a non-test class with that name is not a good practice,
|
||||
since most people will assume it is a test case. Test classes have test methods named testXXX.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.junit.TestClassWithoutTestCasesRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/junit/TestClassWithoutTestCasesRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.TestClassWithoutTestCasesRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/TestClassWithoutTestCasesRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -3183,7 +3183,7 @@ public class SimpleTest extends TestCase {
|
||||
|
||||
Using equalsIgnoreCase() is faster than using toUpperCase/toLowerCase().equals()
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.UnnecessaryCaseChangeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/UnnecessaryCaseChangeRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.UnnecessaryCaseChangeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/UnnecessaryCaseChangeRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -3207,7 +3207,7 @@ boolean answer2 = buz.toUpperCase().equalsIgnoreCase("baz"); // another unnec
|
||||
Avoid the use temporary objects when converting primitives to Strings. Use the static conversion methods
|
||||
on the wrapper classes instead.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.unnecessary.UnnecessaryConversionTemporaryRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UnnecessaryConversionTemporaryRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.UnnecessaryConversionTemporaryRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/UnnecessaryConversionTemporaryRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -3367,7 +3367,7 @@ public boolean test(String s) {
|
||||
An operation on an Immutable object (String, BigDecimal or BigInteger) won't change the object itself
|
||||
since the result of the operation is a new object. Therefore, ignoring the operation result is an error.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.unnecessary.UselessOperationOnImmutableRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UselessOperationOnImmutableRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.UselessOperationOnImmutableRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/UselessOperationOnImmutableRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
|
@ -1,187 +0,0 @@
|
||||
---
|
||||
title: Finalizer
|
||||
summary: These rules deal with different problems that can occur with finalizers.
|
||||
permalink: pmd_rules_java_finalizers.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
editmepath: ../pmd-java/src/main/resources/rulesets/java/finalizers.xml
|
||||
keywords: Finalizer, EmptyFinalizer, FinalizeOnlyCallsSuperFinalize, FinalizeOverloaded, FinalizeDoesNotCallSuperFinalize, FinalizeShouldBeProtected, AvoidCallingFinalize
|
||||
---
|
||||
## AvoidCallingFinalize
|
||||
|
||||
**Since:** PMD 3.0
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
The method Object.finalize() is called by the garbage collector on an object when garbage collection determines
|
||||
that there are no more references to the object. It should not be invoked by application logic.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.finalizers.AvoidCallingFinalizeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/finalizers/AvoidCallingFinalizeRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
void foo() {
|
||||
Bar b = new Bar();
|
||||
b.finalize();
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/finalizers.xml/AvoidCallingFinalize" />
|
||||
```
|
||||
|
||||
## EmptyFinalizer
|
||||
|
||||
**Since:** PMD 1.5
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Empty finalize methods serve no purpose and should be removed.
|
||||
|
||||
```
|
||||
//MethodDeclaration[MethodDeclarator[@Image='finalize'][not(FormalParameters/*)]]
|
||||
/Block[count(*)=0]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Foo {
|
||||
protected void finalize() {}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/finalizers.xml/EmptyFinalizer" />
|
||||
```
|
||||
|
||||
## FinalizeDoesNotCallSuperFinalize
|
||||
|
||||
**Since:** PMD 1.5
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
If the finalize() is implemented, its last action should be to call super.finalize.
|
||||
|
||||
```
|
||||
//MethodDeclaration[MethodDeclarator[@Image='finalize'][not(FormalParameters/*)]]
|
||||
/Block
|
||||
/BlockStatement[last()]
|
||||
[not(Statement/StatementExpression/PrimaryExpression
|
||||
[./PrimaryPrefix[@SuperModifier='true']]
|
||||
[./PrimarySuffix[@Image='finalize']]
|
||||
)
|
||||
]
|
||||
[not(Statement/TryStatement/FinallyStatement
|
||||
/Block/BlockStatement/Statement/StatementExpression/PrimaryExpression
|
||||
[./PrimaryPrefix[@SuperModifier='true']]
|
||||
[./PrimarySuffix[@Image='finalize']]
|
||||
)
|
||||
]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
protected void finalize() {
|
||||
something();
|
||||
// neglected to call super.finalize()
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/finalizers.xml/FinalizeDoesNotCallSuperFinalize" />
|
||||
```
|
||||
|
||||
## FinalizeOnlyCallsSuperFinalize
|
||||
|
||||
**Since:** PMD 1.5
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
If the finalize() is implemented, it should do something besides just calling super.finalize().
|
||||
|
||||
```
|
||||
//MethodDeclaration[MethodDeclarator[@Image="finalize"][not(FormalParameters/*)]]
|
||||
/Block[count(BlockStatement)=1]
|
||||
/BlockStatement[
|
||||
Statement/StatementExpression/PrimaryExpression
|
||||
[./PrimaryPrefix[@SuperModifier='true']]
|
||||
[./PrimarySuffix[@Image='finalize']]
|
||||
]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
protected void finalize() {
|
||||
super.finalize();
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/finalizers.xml/FinalizeOnlyCallsSuperFinalize" />
|
||||
```
|
||||
|
||||
## FinalizeOverloaded
|
||||
|
||||
**Since:** PMD 1.5
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Methods named finalize() should not have parameters. It is confusing and most likely an attempt to
|
||||
overload Object.finalize(). It will not be called by the VM.
|
||||
|
||||
```
|
||||
//MethodDeclaration
|
||||
/MethodDeclarator[@Image='finalize'][FormalParameters[count(*)>0]]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Foo {
|
||||
// this is confusing and probably a bug
|
||||
protected void finalize(int a) {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/finalizers.xml/FinalizeOverloaded" />
|
||||
```
|
||||
|
||||
## FinalizeShouldBeProtected
|
||||
|
||||
**Since:** PMD 1.1
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
When overriding the finalize(), the new method should be set as protected. If made public,
|
||||
other classes may invoke it at inappropriate times.
|
||||
|
||||
```
|
||||
//MethodDeclaration[@Protected="false"]
|
||||
/MethodDeclarator[@Image="finalize"]
|
||||
[not(FormalParameters/*)]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public void finalize() {
|
||||
// do something
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/finalizers.xml/FinalizeShouldBeProtected" />
|
||||
```
|
||||
|
@ -1,175 +0,0 @@
|
||||
---
|
||||
title: Import Statements
|
||||
summary: These rules deal with different problems that can occur with import statements.
|
||||
permalink: pmd_rules_java_imports.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
editmepath: ../pmd-java/src/main/resources/rulesets/java/imports.xml
|
||||
keywords: Import Statements, DuplicateImports, DontImportJavaLang, UnusedImports, ImportFromSamePackage, TooManyStaticImports, UnnecessaryFullyQualifiedName
|
||||
---
|
||||
## DontImportJavaLang
|
||||
|
||||
**Since:** PMD 0.5
|
||||
|
||||
**Priority:** Medium Low (4)
|
||||
|
||||
Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3).
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.imports.DontImportJavaLangRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/imports/DontImportJavaLangRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
import java.lang.String; // this is unnecessary
|
||||
|
||||
public class Foo {}
|
||||
|
||||
// --- in another source code file...
|
||||
|
||||
import java.lang.*; // this is bad
|
||||
|
||||
public class Foo {}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/imports.xml/DontImportJavaLang" />
|
||||
```
|
||||
|
||||
## DuplicateImports
|
||||
|
||||
**Since:** PMD 0.5
|
||||
|
||||
**Priority:** Medium Low (4)
|
||||
|
||||
Duplicate or overlapping import statements should be avoided.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.imports.DuplicateImportsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/imports/DuplicateImportsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
import java.lang.String;
|
||||
import java.lang.*;
|
||||
public class Foo {}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/imports.xml/DuplicateImports" />
|
||||
```
|
||||
|
||||
## ImportFromSamePackage
|
||||
|
||||
**Since:** PMD 1.02
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
There is no need to import a type that lives in the same package.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.imports.ImportFromSamePackageRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/imports/ImportFromSamePackageRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
package foo;
|
||||
|
||||
import foo.Buz; // no need for this
|
||||
import foo.*; // or this
|
||||
|
||||
public class Bar{}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/imports.xml/ImportFromSamePackage" />
|
||||
```
|
||||
|
||||
## TooManyStaticImports
|
||||
|
||||
**Since:** PMD 4.1
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
If you overuse the static import feature, it can make your program unreadable and
|
||||
unmaintainable, polluting its namespace with all the static members you import.
|
||||
Readers of your code (including you, a few months after you wrote it) will not know
|
||||
which class a static member comes from (Sun 1.5 Language Guide).
|
||||
|
||||
```
|
||||
.[count(ImportDeclaration[@Static = 'true']) > $maximumStaticImports]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
import static Lennon;
|
||||
import static Ringo;
|
||||
import static George;
|
||||
import static Paul;
|
||||
import static Yoko; // Too much !
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|maximumStaticImports|4|All static imports can be disallowed by setting this to 0|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/imports.xml/TooManyStaticImports" />
|
||||
```
|
||||
|
||||
## UnnecessaryFullyQualifiedName
|
||||
|
||||
**Since:** PMD 5.0
|
||||
|
||||
**Priority:** Medium Low (4)
|
||||
|
||||
Import statements allow the use of non-fully qualified names. The use of a fully qualified name
|
||||
which is covered by an import statement is redundant. Consider using the non-fully qualified name.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.imports.UnnecessaryFullyQualifiedNameRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/imports/UnnecessaryFullyQualifiedNameRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
import java.util.List;
|
||||
|
||||
public class Foo {
|
||||
private java.util.List list1; // Unnecessary FQN
|
||||
private List list2; // More appropriate given import of 'java.util.List'
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/imports.xml/UnnecessaryFullyQualifiedName" />
|
||||
```
|
||||
|
||||
## UnusedImports
|
||||
|
||||
**Since:** PMD 1.0
|
||||
|
||||
**Priority:** Medium Low (4)
|
||||
|
||||
Avoid unused import statements to prevent unwanted dependencies.
|
||||
This rule will also find unused on demand imports, i.e. import com.foo.*.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.imports.UnusedImportsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/imports/UnusedImportsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
import java.io.File; // not referenced or required
|
||||
import java.util.*; // not referenced or required
|
||||
|
||||
public class Foo {}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/imports.xml/UnusedImports" />
|
||||
```
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,87 +0,0 @@
|
||||
---
|
||||
title: JavaBeans
|
||||
summary: The JavaBeans Ruleset catches instances of bean rules not being followed.
|
||||
permalink: pmd_rules_java_javabeans.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
editmepath: ../pmd-java/src/main/resources/rulesets/java/javabeans.xml
|
||||
keywords: JavaBeans, BeanMembersShouldSerialize, MissingSerialVersionUID
|
||||
---
|
||||
## BeanMembersShouldSerialize
|
||||
|
||||
**Since:** PMD 1.1
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
If a class is a bean, or is referenced by a bean directly or indirectly it needs to be serializable.
|
||||
Member variables need to be marked as transient, static, or have accessor methods in the class. Marking
|
||||
variables as transient is the safest and easiest modification. Accessor methods should follow the Java
|
||||
naming conventions, i.e. for a variable named foo, getFoo() and setFoo() accessor methods should be provided.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.javabeans.BeanMembersShouldSerializeRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/javabeans/BeanMembersShouldSerializeRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
private transient int someFoo; // good, it's transient
|
||||
private static int otherFoo; // also OK
|
||||
private int moreFoo; // OK, has proper accessors, see below
|
||||
private int badFoo; // bad, should be marked transient
|
||||
|
||||
private void setMoreFoo(int moreFoo){
|
||||
this.moreFoo = moreFoo;
|
||||
}
|
||||
|
||||
private int getMoreFoo(){
|
||||
return this.moreFoo;
|
||||
}
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|prefix||A variable prefix to skip, i.e., m_|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/javabeans.xml/BeanMembersShouldSerialize" />
|
||||
```
|
||||
|
||||
## MissingSerialVersionUID
|
||||
|
||||
**Since:** PMD 3.0
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Serializable classes should provide a serialVersionUID field.
|
||||
|
||||
```
|
||||
//ClassOrInterfaceDeclaration
|
||||
[
|
||||
count(ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
|
||||
/FieldDeclaration/VariableDeclarator/VariableDeclaratorId[@Image='serialVersionUID']) = 0
|
||||
and
|
||||
count(ImplementsList
|
||||
[ClassOrInterfaceType/@Image='Serializable'
|
||||
or ClassOrInterfaceType/@Image='java.io.Serializable']) =1
|
||||
and
|
||||
@Abstract = 'false'
|
||||
]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Foo implements java.io.Serializable {
|
||||
String name;
|
||||
// Define serialization id to avoid serialization related bugs
|
||||
// i.e., public static final long serialVersionUID = 4328743;
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/javabeans.xml/MissingSerialVersionUID" />
|
||||
```
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,172 +0,0 @@
|
||||
---
|
||||
title: Jakarta Commons Logging
|
||||
summary: The Jakarta Commons Logging ruleset contains a collection of rules that find questionable usages of that framework.
|
||||
permalink: pmd_rules_java_logging-jakarta-commons.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
editmepath: ../pmd-java/src/main/resources/rulesets/java/logging-jakarta-commons.xml
|
||||
keywords: Jakarta Commons Logging, UseCorrectExceptionLogging, ProperLogger, GuardDebugLogging, GuardLogStatement
|
||||
---
|
||||
## GuardDebugLogging
|
||||
|
||||
**Since:** PMD 4.3
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
When log messages are composed by concatenating strings, the whole section should be guarded
|
||||
by a isDebugEnabled() check to avoid performance and memory issues.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.logging.GuardDebugLoggingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardDebugLoggingRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Test {
|
||||
private static final Log __log = LogFactory.getLog(Test.class);
|
||||
public void test() {
|
||||
// okay:
|
||||
__log.debug("log something");
|
||||
|
||||
// okay:
|
||||
__log.debug("log something with exception", e);
|
||||
|
||||
// bad:
|
||||
__log.debug("log something" + " and " + "concat strings");
|
||||
|
||||
// bad:
|
||||
__log.debug("log something" + " and " + "concat strings", e);
|
||||
|
||||
// good:
|
||||
if (__log.isDebugEnabled()) {
|
||||
__log.debug("bla" + "",e );
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|guardsMethods|[]|method use to guard the log statement|
|
||||
|logLevels|[]|LogLevels to guard|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/logging-jakarta-commons.xml/GuardDebugLogging" />
|
||||
```
|
||||
|
||||
## GuardLogStatement
|
||||
|
||||
**Since:** PMD 5.1.0
|
||||
|
||||
**Priority:** Medium High (2)
|
||||
|
||||
Whenever using a log level, one should check if the loglevel is actually enabled, or
|
||||
otherwise skip the associate String creation and manipulation.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.logging.GuardLogStatementRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardLogStatementRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
// Add this for performance
|
||||
if (log.isDebugEnabled() { ...
|
||||
log.debug("log something" + " and " + "concat strings");
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|guardsMethods|[]|method use to guard the log statement|
|
||||
|logLevels|[]|LogLevels to guard|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/logging-jakarta-commons.xml/GuardLogStatement" />
|
||||
```
|
||||
|
||||
## ProperLogger
|
||||
|
||||
**Since:** PMD 3.3
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
A logger should normally be defined private static final and be associated with the correct class.
|
||||
Private final Log log; is also allowed for rare cases where loggers need to be passed around,
|
||||
with the restriction that the logger needs to be passed into the constructor.
|
||||
|
||||
```
|
||||
//ClassOrInterfaceBodyDeclaration[FieldDeclaration//ClassOrInterfaceType[@Image='Log']
|
||||
and
|
||||
not(FieldDeclaration[@Final='true'][@Static='true'][@Private='true'][.//VariableDeclaratorId[@Image=$staticLoggerName]]
|
||||
//ArgumentList//ClassOrInterfaceType/@Image = ancestor::ClassOrInterfaceDeclaration/@Image)
|
||||
and
|
||||
not(FieldDeclaration[@Final='true'][@Private='true'][.//VariableDeclaratorId[@Image='log']]
|
||||
[count(.//VariableInitializer)=0]
|
||||
[ancestor::ClassOrInterfaceBody//StatementExpression[.//PrimaryExpression/descendant::*[@Image='log']][count(.//AllocationExpression)=0]]
|
||||
)]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Foo {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(Foo.class); // proper way
|
||||
|
||||
protected Log LOG = LogFactory.getLog(Testclass.class); // wrong approach
|
||||
}
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|staticLoggerName|LOG|Name of the static Logger variable|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/logging-jakarta-commons.xml/ProperLogger" />
|
||||
```
|
||||
|
||||
## UseCorrectExceptionLogging
|
||||
|
||||
**Since:** PMD 3.2
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
To make sure the full stacktrace is printed out, use the logging statement with two arguments: a String and a Throwable.
|
||||
|
||||
```
|
||||
//CatchStatement/Block/BlockStatement/Statement/StatementExpression
|
||||
/PrimaryExpression[PrimaryPrefix/Name[starts-with(@Image,
|
||||
concat(ancestor::ClassOrInterfaceDeclaration/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration
|
||||
[Type//ClassOrInterfaceType[@Image='Log']]
|
||||
/VariableDeclarator/VariableDeclaratorId/@Image, '.'))]]
|
||||
[PrimarySuffix/Arguments[@ArgumentCount='1']]
|
||||
[PrimarySuffix/Arguments//Name/@Image = ancestor::CatchStatement/FormalParameter/VariableDeclaratorId/@Image]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Main {
|
||||
private static final Log _LOG = LogFactory.getLog( Main.class );
|
||||
void bar() {
|
||||
try {
|
||||
} catch( Exception e ) {
|
||||
_LOG.error( e ); //Wrong!
|
||||
} catch( OtherException oe ) {
|
||||
_LOG.error( oe.getMessage(), oe ); //Correct
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/logging-jakarta-commons.xml/UseCorrectExceptionLogging" />
|
||||
```
|
||||
|
@ -1,192 +0,0 @@
|
||||
---
|
||||
title: Java Logging
|
||||
summary: The Java Logging ruleset contains a collection of rules that find questionable usages of the logger.
|
||||
permalink: pmd_rules_java_logging-java.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
editmepath: ../pmd-java/src/main/resources/rulesets/java/logging-java.xml
|
||||
keywords: Java Logging, MoreThanOneLogger, LoggerIsNotStaticFinal, SystemPrintln, AvoidPrintStackTrace, GuardLogStatementJavaUtil, InvalidSlf4jMessageFormat
|
||||
---
|
||||
## AvoidPrintStackTrace
|
||||
|
||||
**Since:** PMD 3.2
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Avoid printStackTrace(); use a logger call instead.
|
||||
|
||||
```
|
||||
//PrimaryExpression
|
||||
[PrimaryPrefix/Name[contains(@Image,'printStackTrace')]]
|
||||
[PrimarySuffix[not(boolean(Arguments/ArgumentList/Expression))]]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
class Foo {
|
||||
void bar() {
|
||||
try {
|
||||
// do something
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/logging-java.xml/AvoidPrintStackTrace" />
|
||||
```
|
||||
|
||||
## GuardLogStatementJavaUtil
|
||||
|
||||
**Since:** PMD 5.1.0
|
||||
|
||||
**Priority:** Medium High (2)
|
||||
|
||||
Whenever using a log level, one should check if the loglevel is actually enabled, or
|
||||
otherwise skip the associate String creation and manipulation.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.logging.GuardLogStatementJavaUtilRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardLogStatementJavaUtilRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
//...
|
||||
// Add this for performance
|
||||
if (log.isLoggable(Level.FINE)) {
|
||||
log.fine("log something" + " and " + "concat strings");
|
||||
}
|
||||
```
|
||||
|
||||
**This rule has the following properties:**
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|guardsMethods|[]|method use to guard the log statement|
|
||||
|logLevels|[]|LogLevels to guard|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/logging-java.xml/GuardLogStatementJavaUtil" />
|
||||
```
|
||||
|
||||
## InvalidSlf4jMessageFormat
|
||||
|
||||
**Since:** PMD 5.5.0
|
||||
|
||||
**Priority:** Low (5)
|
||||
|
||||
Check for messages in slf4j loggers with non matching number of arguments and placeholders.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.logging.InvalidSlf4jMessageFormatRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/InvalidSlf4jMessageFormatRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
LOGGER.error("forget the arg {}");
|
||||
LOGGER.error("too many args {}", "arg1", "arg2");
|
||||
LOGGER.error("param {}", "arg1", new IllegalStateException("arg")); //The exception is shown separately, so is correct.
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/logging-java.xml/InvalidSlf4jMessageFormat" />
|
||||
```
|
||||
|
||||
## LoggerIsNotStaticFinal
|
||||
|
||||
**Since:** PMD 2.0
|
||||
|
||||
**Priority:** Medium High (2)
|
||||
|
||||
In most cases, the Logger reference can be declared as static and final.
|
||||
|
||||
```
|
||||
//VariableDeclarator
|
||||
[parent::FieldDeclaration]
|
||||
[../Type/ReferenceType
|
||||
/ClassOrInterfaceType[@Image='Logger']
|
||||
and
|
||||
(..[@Final='false'] or ..[@Static = 'false'] ) ]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Foo{
|
||||
Logger log = Logger.getLogger(Foo.class.getName()); // not recommended
|
||||
|
||||
static final Logger log = Logger.getLogger(Foo.class.getName()); // preferred approach
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/logging-java.xml/LoggerIsNotStaticFinal" />
|
||||
```
|
||||
|
||||
## MoreThanOneLogger
|
||||
|
||||
**Since:** PMD 2.0
|
||||
|
||||
**Priority:** Medium High (2)
|
||||
|
||||
Normally only one logger is used in each class.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.logging.MoreThanOneLoggerRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/MoreThanOneLoggerRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Foo {
|
||||
Logger log = Logger.getLogger(Foo.class.getName());
|
||||
// It is very rare to see two loggers on a class, normally
|
||||
// log information is multiplexed by levels
|
||||
Logger log2= Logger.getLogger(Foo.class.getName());
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/logging-java.xml/MoreThanOneLogger" />
|
||||
```
|
||||
|
||||
## SystemPrintln
|
||||
|
||||
**Since:** PMD 2.1
|
||||
|
||||
**Priority:** Medium High (2)
|
||||
|
||||
References to System.(out|err).print are usually intended for debugging purposes and can remain in
|
||||
the codebase even in production code. By using a logger one can enable/disable this behaviour at
|
||||
will (and by priority) and avoid clogging the Standard out log.
|
||||
|
||||
```
|
||||
//Name[
|
||||
starts-with(@Image, 'System.out.print')
|
||||
or
|
||||
starts-with(@Image, 'System.err.print')
|
||||
]
|
||||
```
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
class Foo{
|
||||
Logger log = Logger.getLogger(Foo.class.getName());
|
||||
public void testA () {
|
||||
System.out.println("Entering test");
|
||||
// Better use this
|
||||
log.fine("Entering test");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/logging-java.xml/SystemPrintln" />
|
||||
```
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Multithreading
|
||||
summary: The Multithreading category contains rules that deal with programming errors in multi-threaded environments.
|
||||
summary: Rules that flag issues when dealing with multiple threads of execution.
|
||||
permalink: pmd_rules_java_multithreading.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
@ -195,7 +195,7 @@ Note: With Java 5, you can make Double checked locking work, if you declare the
|
||||
For more details refer to: <http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html>
|
||||
or <http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html>
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.basic.DoubleCheckedLockingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/DoubleCheckedLockingRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.multithreading.DoubleCheckedLockingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/multithreading/DoubleCheckedLockingRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -238,7 +238,7 @@ performance penalty. [Reference](http://www.cs.umd.edu/~pugh/java/memoryModel/Do
|
||||
|
||||
See Effective Java, item 48.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.NonThreadSafeSingletonRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NonThreadSafeSingletonRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.multithreading.NonThreadSafeSingletonRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/multithreading/NonThreadSafeSingletonRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -276,7 +276,7 @@ SimpleDateFormat instances are not synchronized. Sun recommends using separate f
|
||||
for each thread. If multiple threads must access a static formatter, the formatter must be
|
||||
synchronized either on method or block level.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.UnsynchronizedStaticDateFormatterRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/UnsynchronizedStaticDateFormatterRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.multithreading.UnsynchronizedStaticDateFormatterRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/multithreading/UnsynchronizedStaticDateFormatterRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Performance
|
||||
summary: The Performance category contains rules that deal with optimizations and performance issues.
|
||||
summary: Rules that flag suboptimal code.
|
||||
permalink: pmd_rules_java_performance.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
@ -40,7 +40,7 @@ String t = Integer.toString(456); // preferred approach
|
||||
|
||||
Avoid concatenating characters as strings in StringBuffer/StringBuilder.append methods.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.AppendCharacterWithCharRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/AppendCharacterWithCharRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.AppendCharacterWithCharRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/AppendCharacterWithCharRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -117,7 +117,7 @@ public class Test {
|
||||
|
||||
New objects created within loops should be checked to see if they can created outside them and reused.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.optimizations.AvoidInstantiatingObjectsInLoopsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/AvoidInstantiatingObjectsInLoopsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.AvoidInstantiatingObjectsInLoopsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/AvoidInstantiatingObjectsInLoopsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -178,7 +178,7 @@ public class UsingShort {
|
||||
Don't create instances of already existing BigInteger (BigInteger.ZERO, BigInteger.ONE) and
|
||||
for Java 1.5 onwards, BigInteger.TEN and BigDecimal (BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN)
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.basic.BigIntegerInstantiationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/BigIntegerInstantiationRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.BigIntegerInstantiationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/BigIntegerInstantiationRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -203,7 +203,7 @@ bi4 = new BigInteger(0); // reference BigInteger.ZERO instead
|
||||
|
||||
Avoid instantiating Boolean objects; you can reference Boolean.TRUE, Boolean.FALSE, or call Boolean.valueOf() instead.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.basic.BooleanInstantiationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/BooleanInstantiationRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.BooleanInstantiationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/BooleanInstantiationRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -255,7 +255,7 @@ public class Foo {
|
||||
Consecutive calls to StringBuffer/StringBuilder .append should be chained, reusing the target object. This can improve the performance
|
||||
by producing a smaller bytecode, reducing overhead and improving inlining. A complete analysis can be found [here](https://github.com/pmd/pmd/issues/202#issuecomment-274349067)
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.ConsecutiveAppendsShouldReuseRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/ConsecutiveAppendsShouldReuseRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.ConsecutiveAppendsShouldReuseRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/ConsecutiveAppendsShouldReuseRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -284,7 +284,7 @@ buf.append("Hello").append(foo).append("World"); // good
|
||||
|
||||
Consecutively calling StringBuffer/StringBuilder.append with String literals
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.ConsecutiveLiteralAppendsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/ConsecutiveLiteralAppendsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.ConsecutiveLiteralAppendsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/ConsecutiveLiteralAppendsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -318,7 +318,7 @@ false if a non-whitespace character is found. You can refer to Apache's StringUt
|
||||
Spring's StringUtils#hasText (in the Spring framework) or Google's CharMatcher#whitespace (in Guava) for
|
||||
existing implementations.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.InefficientEmptyStringCheckRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/InefficientEmptyStringCheckRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.InefficientEmptyStringCheckRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientEmptyStringCheckRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -344,7 +344,7 @@ public void bar(String string) {
|
||||
Avoid concatenating non-literals in a StringBuffer constructor or append() since intermediate buffers will
|
||||
need to be be created and destroyed by the JVM.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.InefficientStringBufferingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/InefficientStringBufferingRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.InefficientStringBufferingRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientStringBufferingRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -374,7 +374,7 @@ passed into StringBuffer.append(), but represents a best guess "worst case" scen
|
||||
StringBuffer/StringBuilder constructor initializes the object to 16 characters. This default
|
||||
is assumed if the length of the constructor can not be determined.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.InsufficientStringBufferDeclarationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/InsufficientStringBufferDeclarationRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.InsufficientStringBufferDeclarationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InsufficientStringBufferDeclarationRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -498,7 +498,7 @@ Foo[] fooArray = foos.toArray(new Foo[foos.size()]);
|
||||
Java will initialize fields with known default values so any explicit initialization of those same defaults
|
||||
is redundant and results in a larger class file (approximately three additional bytecode instructions per field).
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.optimizations.RedundantFieldInitializerRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/RedundantFieldInitializerRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.RedundantFieldInitializerRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/RedundantFieldInitializerRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -609,7 +609,7 @@ public class Foo {
|
||||
|
||||
Avoid instantiating String objects; this is usually unnecessary since they are immutable and can be safely shared.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.StringInstantiationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/StringInstantiationRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.StringInstantiationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/StringInstantiationRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -630,7 +630,7 @@ private String bar = new String("bar"); // just do a String bar = "bar";
|
||||
|
||||
Avoid calling toString() on objects already known to be string instances; this is unnecessary.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.StringToStringRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/StringToStringRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.StringToStringRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/StringToStringRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -700,7 +700,7 @@ Most wrapper classes provide static conversion methods that avoid the need to cr
|
||||
just to create the primitive forms. Using these avoids the cost of creating objects that also need to be
|
||||
garbage-collected later.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.optimizations.UnnecessaryWrapperObjectCreationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/UnnecessaryWrapperObjectCreationRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.UnnecessaryWrapperObjectCreationRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/UnnecessaryWrapperObjectCreationRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -827,7 +827,7 @@ public class Test {
|
||||
|
||||
Use String.indexOf(char) when checking for the index of a single character; it executes faster.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.UseIndexOfCharRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/UseIndexOfCharRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.UseIndexOfCharRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/UseIndexOfCharRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -852,7 +852,7 @@ if (s.indexOf('d') {}
|
||||
|
||||
No need to call String.valueOf to append to a string; just use the valueOf() argument directly.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.UselessStringValueOfRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/UselessStringValueOfRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.UselessStringValueOfRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/UselessStringValueOfRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -880,7 +880,7 @@ The use of the '+=' operator for appending strings causes the JVM to create and
|
||||
If a non-trivial number of these concatenations are being used then the explicit use of a StringBuilder or
|
||||
threadsafe StringBuffer is recommended to avoid this.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.optimizations.UseStringBufferForStringAppendsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/UseStringBufferForStringAppendsRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.UseStringBufferForStringAppendsRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/UseStringBufferForStringAppendsRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
@ -911,7 +911,7 @@ public class Foo {
|
||||
Use StringBuffer.length() to determine StringBuffer length rather than using StringBuffer.toString().equals("")
|
||||
or StringBuffer.toString().length() == ...
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.strings.UseStringBufferLengthRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/strings/UseStringBufferLengthRule.java)
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.performance.UseStringBufferLengthRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/UseStringBufferLengthRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,65 +0,0 @@
|
||||
---
|
||||
title: Security Code Guidelines
|
||||
summary: These rules check the security guidelines from Sun, published at http://java.sun.com/security/seccodeguide.html#gcg
|
||||
permalink: pmd_rules_java_sunsecure.html
|
||||
folder: pmd/rules/java
|
||||
sidebaractiveurl: /pmd_rules_java.html
|
||||
editmepath: ../pmd-java/src/main/resources/rulesets/java/sunsecure.xml
|
||||
keywords: Security Code Guidelines, MethodReturnsInternalArray, ArrayIsStoredDirectly
|
||||
---
|
||||
## ArrayIsStoredDirectly
|
||||
|
||||
**Since:** PMD 2.2
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Constructors and methods receiving arrays should clone objects and store the copy.
|
||||
This prevents future changes from the user from affecting the original array.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.sunsecure.ArrayIsStoredDirectlyRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/sunsecure/ArrayIsStoredDirectlyRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Foo {
|
||||
private String [] x;
|
||||
public void foo (String [] param) {
|
||||
// Don't do this, make a copy of the array at least
|
||||
this.x=param;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/sunsecure.xml/ArrayIsStoredDirectly" />
|
||||
```
|
||||
|
||||
## MethodReturnsInternalArray
|
||||
|
||||
**Since:** PMD 2.2
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Exposing internal arrays to the caller violates object encapsulation since elements can be
|
||||
removed or replaced outside of the object that owns it. It is safer to return a copy of the array.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.sunsecure.MethodReturnsInternalArrayRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/sunsecure/MethodReturnsInternalArrayRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class SecureSystem {
|
||||
UserData [] ud;
|
||||
public UserData [] getUserData() {
|
||||
// Don't return directly the internal array, return a copy
|
||||
return ud;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
<rule ref="rulesets/java/sunsecure.xml/MethodReturnsInternalArray" />
|
||||
```
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user