forked from phoedos/pmd
Merge branch 'master'
This commit is contained in:
@ -29,10 +29,11 @@ When filing a bug report, please provide as much information as possible, so tha
|
||||
|
||||
## Documentation
|
||||
|
||||
There is some documentation available under <https://pmd.github.io>. Feel free to create a bug report if
|
||||
documentation is missing, incomplete or outdated.
|
||||
There is some documentation available under <https://pmd.github.io/pmd>. Feel free to create a bug report if
|
||||
documentation is missing, incomplete or outdated. See [Bug reports](#bug-reports).
|
||||
|
||||
The documentation is generated as a maven site, the source is available at: <https://github.com/pmd/pmd/tree/master/src/site>
|
||||
The documentation is generated as a Jekyll site, the source is available at: <https://github.com/pmd/pmd/tree/master/docs>. You can find build instructions there.
|
||||
For more on contributing documentation check <https://pmd.github.io/pmd/pmd_devdocs_writing_documentation.html>
|
||||
|
||||
## Questions
|
||||
|
||||
|
@ -17,13 +17,48 @@ The pages are in general in [Github Flavored Markdown](https://kramdown.gettalon
|
||||
|
||||
## Structure
|
||||
|
||||
All documentation is stored in the folder `docs/`. This is the folder, that github and the travis-ci scripts
|
||||
use to render the site.
|
||||
The documentation sources can be found in two places based on how they are generated:
|
||||
- the ones that are manually written (like the one you are reading);
|
||||
- and the ones that are generated automatically from the category files. All the rule documentation
|
||||
pages are generated that way.
|
||||
|
||||
New pages are stored in the different subfolders under `pages`. The folder structure resembles the sidebar structure.
|
||||
### Handwritten documentation
|
||||
|
||||
All handwritten documentation is stored in the subfolders under `docs/pages`. The folder structure resembles the sidebar structure.
|
||||
Since all pages use a simple *permalink*, in the rendered html pages, all pages are flattened in one directory.
|
||||
This makes it easy to view the documentation also offline.
|
||||
|
||||
### Rule documentation
|
||||
|
||||
The categories for a language `%lang%` are located in
|
||||
`pmd-%lang%/src/main/resources/category/%lang% `. So for Java the categories
|
||||
can be found under [pmd-java/src/main/resources/category/java](https://github.com/pmd/pmd/tree/master/pmd-java/src/main/resources/category/java).
|
||||
The XML category files in this directory are transformed during build into markdown pages
|
||||
describing the rules they contain. These pages are placed under `docs/` like the handwritten
|
||||
documentation, and are then rendered with Jekyll like the rest of them. The rule documentation
|
||||
generator is the separate submodule `pmd-doc`.
|
||||
|
||||
Modifying the documentation of a rule should thus not be done on the markdown page,
|
||||
but directly on the XML `rule` tag corresponding to the rule, in the relevant
|
||||
category file.
|
||||
|
||||
The XML documentation of rules can contain GitHub flavoured markdown.
|
||||
Just wrap the markdown inside CDATA section in the xml. CDATA sections preserve
|
||||
all formatting inside the delimiters, and allow to write code samples without
|
||||
escaping special xml characters. For example:
|
||||
```
|
||||
<rule ...>
|
||||
<description>
|
||||
<![CDATA[
|
||||
Full description, can contain markup
|
||||
|
||||
And paragraphs
|
||||
]]>
|
||||
</description>
|
||||
...
|
||||
</rule>
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
There are two ways, to execute jekyll:
|
||||
|
@ -119,7 +119,7 @@ folder: pmd/rules
|
||||
* [AvoidDeeplyNestedIfStmts](pmd_rules_java_design.html#avoiddeeplynestedifstmts): Avoid creating deeply nested if-then statements since they are harder to read and error-prone to ...
|
||||
* [AvoidRethrowingException](pmd_rules_java_design.html#avoidrethrowingexception): Catch blocks that merely rethrow a caught exception only add to code size and runtime complexity.
|
||||
* [AvoidThrowingNewInstanceOfSameException](pmd_rules_java_design.html#avoidthrowingnewinstanceofsameexception): Catch blocks that merely rethrow a caught exception wrapped inside a new instance of the same typ...
|
||||
* [AvoidThrowingNullPointerException](pmd_rules_java_design.html#avoidthrowingnullpointerexception): Avoid throwing NullPointerExceptions. These are confusing because most people will assume that th...
|
||||
* [AvoidThrowingNullPointerException](pmd_rules_java_design.html#avoidthrowingnullpointerexception): Avoid throwing NullPointerExceptions manually. These are confusing because most people will assum...
|
||||
* [AvoidThrowingRawExceptionTypes](pmd_rules_java_design.html#avoidthrowingrawexceptiontypes): Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable,Excep...
|
||||
* [ClassWithOnlyPrivateConstructorsShouldBeFinal](pmd_rules_java_design.html#classwithonlyprivateconstructorsshouldbefinal): A class with only private constructors should be final, unless the private constructoris invoked ...
|
||||
* [CollapsibleIfStatements](pmd_rules_java_design.html#collapsibleifstatements): Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with...
|
||||
|
@ -794,9 +794,6 @@ public class SecureSystem {
|
||||
Annotating overridden methods with @Override ensures at compile time that
|
||||
the method really overrides one, which helps refactoring and clarifies intent.
|
||||
|
||||
This rule is limited to resolving methods inherited from non-parameterized
|
||||
or raw supertypes.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.bestpractices.MissingOverrideRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/MissingOverrideRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
@ -193,9 +193,33 @@ public void bar() {
|
||||
|
||||
**Priority:** High (1)
|
||||
|
||||
Avoid throwing NullPointerExceptions. These are confusing because most people will assume that the
|
||||
virtual machine threw it. Consider using an IllegalArgumentException instead; this will be
|
||||
clearly seen as a programmer-initiated exception.
|
||||
Avoid throwing NullPointerExceptions manually. These are confusing because most people will assume that the
|
||||
virtual machine threw it. To avoid a method being called with a null parameter, you may consider
|
||||
using an IllegalArgumentException instead, making it clearly seen as a programmer-initiated exception.
|
||||
However, there are better ways to handle this:
|
||||
|
||||
>*Effective Java, 3rd Edition, Item 72: Favor the use of standard exceptions*
|
||||
>
|
||||
>Arguably, every erroneous method invocation boils down to an illegal argument or state,
|
||||
but other exceptions are standardly used for certain kinds of illegal arguments and states.
|
||||
If a caller passes null in some parameter for which null values are prohibited, convention dictates that
|
||||
NullPointerException be thrown rather than IllegalArgumentException.
|
||||
|
||||
To implement that, you are encouraged to use `java.util.Objects.requireNonNull()`
|
||||
(introduced in Java 1.7). This method is designed primarily for doing parameter
|
||||
validation in methods and constructors with multiple parameters.
|
||||
|
||||
Your parameter validation could thus look like the following:
|
||||
```
|
||||
public class Foo {
|
||||
private String exampleValue;
|
||||
|
||||
void setExampleValue(String exampleValue) {
|
||||
// check, throw and assignment in a single standard call
|
||||
this.exampleValue = Objects.requireNonNull(exampleValue, "exampleValue must not be null!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
//AllocationExpression/ClassOrInterfaceType[@Image='NullPointerException']
|
||||
|
@ -79,9 +79,13 @@ On both scenarios, disabling the cache takes precedence over setting a cache loc
|
||||
* java-codestyle
|
||||
* [#983](https://github.com/pmd/pmd/issues/983): \[java] Detect annotations with single value element
|
||||
* java-design
|
||||
* [#832](https://github.com/pmd/pmd/issues/832): \[java] AvoidThrowingNullPointerException documentation suggestion
|
||||
* [#837](https://github.com/pmd/pmd/issues/837): \[java] CFGs of declared but not called lambdas are treated as parts of an enclosing method's CFG
|
||||
* [#839](https://github.com/pmd/pmd/issues/839): \[java] SignatureDeclareThrowsException's IgnoreJUnitCompletely property not honored for constructors
|
||||
* [#968](https://github.com/pmd/pmd/issues/968): \[java] UseUtilityClassRule reports false positive with lombok NoArgsConstructor
|
||||
* documentation
|
||||
* [#978](https://github.com/pmd/pmd/issues/978): \[core] Broken link in CONTRIBUTING.md
|
||||
* [#992](https://github.com/pmd/pmd/issues/992): \[core] Include info about rule doc generation in "Writing Documentation" md page
|
||||
|
||||
### API Changes
|
||||
|
||||
@ -106,4 +110,7 @@ On both scenarios, disabling the cache takes precedence over setting a cache loc
|
||||
* [#969](https://github.com/pmd/pmd/pull/969): \[java] Issue 968 Add logic to handle lombok private constructors with utility classes - [Kirk Clemens](https://github.com/clem0110)
|
||||
* [#970](https://github.com/pmd/pmd/pull/970): \[java] Fixed inefficient use of keySet iterator instead of entrySet iterator - [Andrey Mochalov](https://github.com/epidemia)
|
||||
* [#984](https://github.com/pmd/pmd/pull/984): \[java] issue983 Add new UnnecessaryAnnotationValueElement rule - [Kirk Clemens](https://github.com/clem0110)
|
||||
* [#989](https://github.com/pmd/pmd/pull/989): \[core] Update Contribute.md to close Issue #978 - [Bolarinwa Saheed Olayemi](https://github.com/refactormyself)
|
||||
* [#990](https://github.com/pmd/pmd/pull/990): \[java] Updated Doc on AvoidThrowingNullPointerException to close Issue #832 - [Bolarinwa Saheed Olayemi](https://github.com/refactormyself)
|
||||
* [#993](https://github.com/pmd/pmd/pull/993): \[core] Update writing_documentation.md to fix Issue #992 - [Bolarinwa Saheed Olayemi](https://github.com/refactormyself)
|
||||
|
||||
|
@ -12,8 +12,10 @@
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
<java.version>8</java.version>
|
||||
<!-- Workaround for https://youtrack.jetbrains.com/issue/IDEA-188690 -->
|
||||
<maven.compiler.source>1.${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>1.${java.version}</maven.compiler.target>
|
||||
<apex.jorje.version>2017-11-17</apex.jorje.version>
|
||||
</properties>
|
||||
|
||||
|
@ -11,9 +11,10 @@
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
|
||||
<java.version>8</java.version>
|
||||
<!-- Workaround for https://youtrack.jetbrains.com/issue/IDEA-188690 -->
|
||||
<maven.compiler.source>1.${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>1.${java.version}</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
@ -10,10 +10,6 @@
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}</config.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -1,119 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="dogfood-goal"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
<description>Dogfood goal, delete this when we reach it.</description>
|
||||
|
||||
<!-- Exclude JavaCC generated artifacts -->
|
||||
<exclude-pattern>.*net/sourceforge/pmd/lang/ast/JavaCharStream.java</exclude-pattern>
|
||||
<exclude-pattern>.*net/sourceforge/pmd/lang/ast/SimpleCharStream.java</exclude-pattern>
|
||||
<exclude-pattern>.*net/sourceforge/pmd/lang/ast/TokenMgrError.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/.*Parser.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/.*ParserConstants.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/.*ParserTokenManager.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/.*ParserTreeConstants.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/.*ParserVisitor.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/JJT.*ParserState.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/ParseException.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/Token.java</exclude-pattern>
|
||||
|
||||
<rule ref="rulesets/internal/pmdspecific.xml"/>
|
||||
|
||||
<rule ref="rulesets/java/basic.xml">
|
||||
<exclude name="CollapsibleIfStatements"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/braces.xml"/>
|
||||
|
||||
<rule ref="rulesets/java/clone.xml"/>
|
||||
|
||||
<rule ref="rulesets/java/controversial.xml">
|
||||
<exclude name="AvoidLiteralsInIfCondition"/>
|
||||
<exclude name="OnlyOneReturn"/>
|
||||
<exclude name="AtLeastOneConstructor"/>
|
||||
<exclude name="CallSuperInConstructor"/>
|
||||
<exclude name="DefaultPackage"/>
|
||||
<exclude name="BooleanInversion"/>
|
||||
<exclude name="DataflowAnomalyAnalysis"/>
|
||||
<exclude name="AvoidFinalLocalVariable"/>
|
||||
<exclude name="DataflowAnomalyAnalysis"/>
|
||||
<exclude name="AssignmentInOperand"/>
|
||||
<exclude name="NullAssignment"/>
|
||||
<exclude name="UseObjectForClearerAPI"/>
|
||||
</rule>
|
||||
<rule ref="rulesets/java/controversial.xml/AssignmentInOperand">
|
||||
<properties>
|
||||
<property name="allowWhile" value="true"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/coupling.xml">
|
||||
<exclude name="CouplingBetweenObjects"/>
|
||||
<exclude name="ExcessiveImports"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/design.xml">
|
||||
<exclude name="UseSingleton"/>
|
||||
<exclude name="AvoidDeeplyNestedIfStmts"/>
|
||||
<exclude name="AvoidReassigningParameters"/>
|
||||
<exclude name="SwitchDensity"/>
|
||||
<exclude name="ConstructorCallsOverridableMethod"/>
|
||||
<exclude name="SimpleDateFormatNeedsLocale"/>
|
||||
<exclude name="ImmutableField"/>
|
||||
<exclude name="UseLocaleWithCaseConversions"/>
|
||||
<!-- TODO Is AvoidSynchronizedAtMethodLevel something we should shoot for? -->
|
||||
<exclude name="AvoidSynchronizedAtMethodLevel"/>
|
||||
<exclude name="EmptyMethodInAbstractClassShouldBeAbstract"/>
|
||||
<exclude name="ReturnEmptyArrayRatherThanNull"/>
|
||||
<exclude name="TooFewBranchesForASwitchStatement"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/empty.xml">
|
||||
<exclude name="EmptyCatchBlock" />
|
||||
</rule>
|
||||
<rule ref="rulesets/java/empty.xml/EmptyCatchBlock">
|
||||
<properties>
|
||||
<property name="allowCommentedBlocks" description="blah blah" value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/finalizers.xml"/>
|
||||
|
||||
<rule ref="rulesets/java/imports.xml"/>
|
||||
|
||||
<rule ref="rulesets/java/logging-java.xml">
|
||||
</rule>
|
||||
|
||||
<!-- Specifically reference via other referencing RuleSets to test Reference to Reference -->
|
||||
<rule ref="rulesets/java/migrating_to_13.xml"/>
|
||||
<rule ref="rulesets/java/migrating_to_14.xml"/>
|
||||
<rule ref="rulesets/java/migrating_to_15.xml"/>
|
||||
|
||||
<rule ref="rulesets/java/naming.xml">
|
||||
<exclude name="ShortVariable"/>
|
||||
<exclude name="LongVariable"/>
|
||||
<exclude name="ShortMethodName"/>
|
||||
<exclude name="ShortClassName"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/optimizations.xml">
|
||||
<exclude name="MethodArgumentCouldBeFinal"/>
|
||||
<exclude name="LocalVariableCouldBeFinal"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/strictexception.xml">
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/strings.xml">
|
||||
<exclude name="AvoidDuplicateLiterals"/>
|
||||
<exclude name="InefficientEmptyStringCheck"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/unnecessary.xml"/>
|
||||
|
||||
<rule ref="rulesets/java/unusedcode.xml">
|
||||
<exclude name="UnusedFormalParameter"/>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
@ -1,212 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="dogfood"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
<description>Rules to check PMD itself. This RuleSet is written to include all Rules,
|
||||
and exclude those which we know are explicitly decided as not applicable to PMD itself.
|
||||
This is the most encompassing form of RuleSet.</description>
|
||||
|
||||
<!-- Exclude JavaCC generated artifacts -->
|
||||
<exclude-pattern>.*net/sourceforge/pmd/lang/ast/JavaCharStream.java</exclude-pattern>
|
||||
<exclude-pattern>.*net/sourceforge/pmd/lang/ast/SimpleCharStream.java</exclude-pattern>
|
||||
<exclude-pattern>.*net/sourceforge/pmd/lang/ast/TokenMgrError.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/.*Parser.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/.*ParserConstants.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/.*ParserTokenManager.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/.*ParserTreeConstants.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/.*ParserVisitor.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/JJT.*ParserState.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/ParseException.java</exclude-pattern>
|
||||
<exclude-pattern>.*lang/(java|jsp|cpp)/ast/Token.java</exclude-pattern>
|
||||
|
||||
<!-- TODO First step is to re-enable these Rules from the original dogfood, as these are subjectively most important:
|
||||
UnusedPrivateField
|
||||
AvoidCatchingThrowable
|
||||
EmptyCatchBlock
|
||||
-->
|
||||
|
||||
<rule ref="rulesets/internal/pmdspecific.xml"/>
|
||||
|
||||
<rule ref="rulesets/java/basic.xml">
|
||||
<exclude name="CollapsibleIfStatements"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/braces.xml"/>
|
||||
|
||||
<rule ref="rulesets/java/clone.xml"/>
|
||||
|
||||
<!-- Nothing here applies to PMD
|
||||
<rule ref="rulesets/java/codesize.xml"/>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
<rule ref="rulesets/java/controversial.xml">
|
||||
<exclude name="AvoidLiteralsInIfCondition"/>
|
||||
<exclude name="OnlyOneReturn"/>
|
||||
<exclude name="AtLeastOneConstructor"/>
|
||||
<exclude name="CallSuperInConstructor"/>
|
||||
<exclude name="DefaultPackage"/>
|
||||
<exclude name="DataflowAnomalyAnalysis"/>
|
||||
<exclude name="AvoidFinalLocalVariable"/>
|
||||
<exclude name="DataflowAnomalyAnalysis"/>
|
||||
<exclude name="AssignmentInOperand"/>
|
||||
<exclude name="NullAssignment"/>
|
||||
<exclude name="UseObjectForClearerAPI"/>
|
||||
<exclude name="UseConcurrentHashMap"/>
|
||||
</rule>
|
||||
<rule ref="rulesets/java/controversial.xml/AssignmentInOperand">
|
||||
<properties>
|
||||
<property name="allowWhile" value="true"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/coupling.xml">
|
||||
<exclude name="CouplingBetweenObjects"/>
|
||||
<exclude name="ExcessiveImports"/>
|
||||
<exclude name="LawOfDemeter"/>
|
||||
<exclude name="LoosePackageCoupling"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/design.xml">
|
||||
<exclude name="UseUtilityClass"/>
|
||||
<exclude name="AvoidDeeplyNestedIfStmts"/>
|
||||
<exclude name="AvoidReassigningParameters"/>
|
||||
<exclude name="SwitchDensity"/>
|
||||
<exclude name="ConstructorCallsOverridableMethod"/>
|
||||
<exclude name="SimpleDateFormatNeedsLocale"/>
|
||||
<exclude name="ImmutableField"/>
|
||||
<exclude name="UseLocaleWithCaseConversions"/>
|
||||
<!-- TODO Is AvoidSynchronizedAtMethodLevel something we should shoot for? -->
|
||||
<exclude name="AvoidSynchronizedAtMethodLevel"/>
|
||||
<exclude name="EmptyMethodInAbstractClassShouldBeAbstract"/>
|
||||
<exclude name="ReturnEmptyArrayRatherThanNull"/>
|
||||
<exclude name="TooFewBranchesForASwitchStatement"/>
|
||||
<exclude name="ConfusingTernary"/>
|
||||
<!-- TODO Work towards enabling the following, disabled for now because of failing code -->
|
||||
<exclude name="PositionLiteralsFirstInComparisons"/>
|
||||
<exclude name="PreserveStackTrace"/>
|
||||
<exclude name="UncommentedEmptyConstructor"/>
|
||||
<exclude name="UncommentedEmptyMethodBody"/>
|
||||
<exclude name="UnnecessaryLocalBeforeReturn"/>
|
||||
<exclude name="AbstractClassWithoutAbstractMethod"/>
|
||||
<exclude name="AccessorClassGeneration"/>
|
||||
<exclude name="SimplifyBooleanExpressions"/>
|
||||
<exclude name="UseVarargs"/>
|
||||
<exclude name="FieldDeclarationsShouldBeAtStartOfClass"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/empty.xml">
|
||||
<exclude name="EmptyCatchBlock" />
|
||||
<!-- TODO Work towards enabling the following, disabled for now because of failing code -->
|
||||
<exclude name="EmptyIfStmt" />
|
||||
</rule>
|
||||
<!-- TODO Work towards enabling the following, disabled for now because of failing code -->
|
||||
<!--
|
||||
<rule ref="rulesets/java/empty.xml/EmptyCatchBlock">
|
||||
<properties>
|
||||
<property name="allowCommentedBlocks" value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
<rule ref="rulesets/java/finalizers.xml"/>
|
||||
|
||||
<rule ref="rulesets/java/imports.xml"/>
|
||||
|
||||
<!-- Nothing here applies to PMD
|
||||
<rule ref="rulesets/java/j2ee.xml"/>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
<!-- Nothing here applies to PMD
|
||||
<rule ref="rulesets/java/javabeans.xml"/>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
<!-- Nothing here applies to PMD
|
||||
<rule ref="rulesets/java/junit.xml"/>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
<!-- Nothing here applies to PMD
|
||||
<rule ref="rulesets/java/logging-jakarta-commons.xml"/>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
<rule ref="rulesets/java/logging-java.xml">
|
||||
<!-- TODO Work towards enabling the following, disabled for now because of failing code -->
|
||||
<exclude name="SystemPrintln"/>
|
||||
<exclude name="AvoidPrintStackTrace"/>
|
||||
</rule>
|
||||
|
||||
<!-- Specifically reference via other referencing RuleSets to test Reference to Reference -->
|
||||
<rule ref="rulesets/java/migrating_to_13.xml"/>
|
||||
<rule ref="rulesets/java/migrating_to_14.xml"/>
|
||||
<rule ref="rulesets/java/migrating_to_15.xml"/>
|
||||
|
||||
<rule ref="rulesets/java/naming.xml">
|
||||
<exclude name="ShortVariable"/>
|
||||
<exclude name="LongVariable"/>
|
||||
<exclude name="ShortMethodName"/>
|
||||
<exclude name="ShortClassName"/>
|
||||
<!-- TODO Work towards enabling the following, disabled for now because of failing code -->
|
||||
<exclude name="AvoidFieldNameMatchingMethodName"/>
|
||||
<exclude name="AbstractNaming"/>
|
||||
<exclude name="MethodNamingConventions"/>
|
||||
<exclude name="AvoidFieldNameMatchingTypeName"/>
|
||||
<exclude name="BooleanGetMethodName"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/optimizations.xml">
|
||||
<exclude name="MethodArgumentCouldBeFinal"/>
|
||||
<exclude name="LocalVariableCouldBeFinal"/>
|
||||
<!-- TODO Work towards enabling the following, disabled for now because of failing code -->
|
||||
<exclude name="AvoidInstantiatingObjectsInLoops"/>
|
||||
<exclude name="RedundantFieldInitializer"/>
|
||||
<exclude name="UseStringBufferForStringAppends"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/strictexception.xml">
|
||||
<!-- TODO Work towards enabling the following, disabled for now because of failing code -->
|
||||
<exclude name="AvoidCatchingGenericException"/>
|
||||
<exclude name="AvoidThrowingRawExceptionTypes"/>
|
||||
<exclude name="SignatureDeclareThrowsException"/>
|
||||
<exclude name="DoNotThrowExceptionInFinally"/>
|
||||
<exclude name="AvoidCatchingThrowable"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/java/strings.xml">
|
||||
<exclude name="AvoidDuplicateLiterals"/>
|
||||
<exclude name="InefficientEmptyStringCheck"/>
|
||||
<!-- TODO Work towards enabling the following, disabled for now because of failing code -->
|
||||
<exclude name="ConsecutiveLiteralAppends"/>
|
||||
<exclude name="InefficientStringBuffering"/>
|
||||
</rule>
|
||||
|
||||
<!-- TODO should we apply these? -->
|
||||
<!--
|
||||
<rule ref="rulesets/java/sunsecure.xml"/>
|
||||
-->
|
||||
|
||||
<rule ref="rulesets/java/unnecessary.xml"/>
|
||||
|
||||
<rule ref="rulesets/java/unusedcode.xml">
|
||||
<exclude name="UnusedFormalParameter"/>
|
||||
<!-- TODO Work towards enabling the following, disabled for now because of failing code -->
|
||||
<exclude name="UnusedPrivateField"/>
|
||||
</rule>
|
||||
|
||||
<!-- Don't let the Language specific APIs leak out -->
|
||||
<!--
|
||||
<rule name="LanguageLoosePackageCoupling" ref="rulesets/java/coupling.xml/LoosePackageCoupling">
|
||||
<properties>
|
||||
<property name="packages"><value>net.sourceforge.pmd.lang,net.sourceforge.pmd.lang.java,net.sourceforge.pmd.lang.jsp,net.sourceforge.pmd.lang.ecmascript,net.sourceforge.pmd.lang.cpp</value></property>
|
||||
<property name="classes">
|
||||
<value>net.sourceforge.pmd.lang.Language,net.sourceforge.pmd.lang.LanguageVersion,net.sourceforge.pmd.lang.LanguageVersionDiscoverer,net.sourceforge.pmd.lang.LanguageVersionHandler,net.sourceforge.pmd.lang.Parser,net.sourceforge.pmd.lang.ast.Node</value>
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
</ruleset>
|
@ -1,62 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="PMD specific rules"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
<description>These rules check for problems that are specific to the PMD codebase and may not be applicable to other projects.</description>
|
||||
|
||||
<rule name="UseInstanceOftoCompareClasses"
|
||||
language="java" since="5.0"
|
||||
message="replace o.getClass().equals(MyClass.class) with o instanceof MyClass"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule">
|
||||
<description>replace o.getClass().equals(MyClass.class) with o instanceof MyClass. Make sure MyClass doesn't have descendants</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//PrimaryExpression[
|
||||
(PrimaryPrefix[Name[ends-with(@Image, 'getClass')]] or PrimarySuffix[@Image='getClass'])
|
||||
and
|
||||
PrimarySuffix[Arguments[count(ArgumentList)=0]]
|
||||
and
|
||||
PrimarySuffix[@Image='equals']
|
||||
and
|
||||
PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix
|
||||
/ResultType/Type/ReferenceType/ClassOrInterfaceType
|
||||
]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule name="ReversedUseInstanceOftoCompareClasses"
|
||||
language="java" since="5.0"
|
||||
message="replace MyClass.class.equals(o.getClass()) with o instanceof MyClass"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule">
|
||||
<description>replace MyClass.class.equals(o.getClass()) with o instanceof MyClass. Make sure MyClass doesn't have descendants</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//PrimaryExpression[
|
||||
PrimaryPrefix[ResultType/Type/ReferenceType/ClassOrInterfaceType]
|
||||
and
|
||||
PrimarySuffix[@Image='equals']
|
||||
and
|
||||
PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression[
|
||||
PrimaryPrefix[Name[ends-with(@Image, 'getClass')]]
|
||||
and
|
||||
PrimarySuffix[Arguments[count(ArgumentList)=0]]
|
||||
]
|
||||
]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
@ -1,15 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="regress-dogfood-goal"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
<description>Rules to check PMD itself.</description>
|
||||
|
||||
<exclude-pattern>.*/xml/.*.java</exclude-pattern>
|
||||
|
||||
<rule ref="rulesets/java/junit.xml">
|
||||
<exclude name="JUnitTestContainsTooManyAsserts"/>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
@ -1,18 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="regress-dogfood"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
<description>Rules to check PMD itself.</description>
|
||||
|
||||
<exclude-pattern>.*/xml/.*.java</exclude-pattern>
|
||||
|
||||
<rule ref="rulesets/java/junit.xml">
|
||||
<exclude name="JUnitAssertionsShouldIncludeMessage"/>
|
||||
<exclude name="JUnitTestsShouldIncludeAssert"/>
|
||||
<exclude name="UseAssertTrueInsteadOfAssertEquals"/>
|
||||
<exclude name="JUnitTestContainsTooManyAsserts"/>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
@ -10,10 +10,6 @@
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -10,10 +10,6 @@
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -11,10 +11,6 @@
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -13,7 +13,9 @@
|
||||
|
||||
<properties>
|
||||
<java.version>8</java.version>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
<!-- Workaround for https://youtrack.jetbrains.com/issue/IDEA-188690 -->
|
||||
<maven.compiler.source>1.${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>1.${java.version}</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
@ -10,10 +10,6 @@
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -10,10 +10,6 @@
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -10,10 +10,6 @@
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -10,10 +10,6 @@
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<testResources>
|
||||
<testResource>
|
||||
|
@ -5,6 +5,7 @@
|
||||
package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName;
|
||||
|
||||
@ -46,7 +47,12 @@ public interface ASTAnyTypeDeclaration extends TypeNode, JavaQualifiableNode, Ac
|
||||
* The kind of type this node declares.
|
||||
*/
|
||||
enum TypeKind {
|
||||
CLASS, INTERFACE, ENUM, ANNOTATION
|
||||
CLASS, INTERFACE, ENUM, ANNOTATION;
|
||||
|
||||
|
||||
public String getPrintableName() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.qname.JavaOperationQualifiedName;
|
||||
|
||||
|
||||
@ -34,7 +36,11 @@ public interface MethodLikeNode extends AccessNode, JavaQualifiableNode, JavaNod
|
||||
enum MethodLikeKind {
|
||||
METHOD,
|
||||
CONSTRUCTOR,
|
||||
LAMBDA
|
||||
LAMBDA;
|
||||
|
||||
public String getPrintableName() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,14 +6,12 @@ package net.sourceforge.pmd.lang.java.rule.design;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.MethodLikeNode;
|
||||
import net.sourceforge.pmd.lang.java.ast.MethodLikeNode.MethodLikeKind;
|
||||
import net.sourceforge.pmd.lang.java.metrics.JavaMetrics;
|
||||
import net.sourceforge.pmd.lang.java.metrics.api.JavaClassMetricKey;
|
||||
import net.sourceforge.pmd.lang.java.metrics.api.JavaOperationMetricKey;
|
||||
@ -126,7 +124,7 @@ public class CyclomaticComplexityRule extends AbstractJavaMetricsRule {
|
||||
if (classWmc >= classReportLevel) {
|
||||
int classHighest = (int) JavaMetrics.get(JavaOperationMetricKey.CYCLO, node, cycloOptions, ResultOption.HIGHEST);
|
||||
|
||||
String[] messageParams = {node.getTypeKind().name().toLowerCase(Locale.ROOT),
|
||||
String[] messageParams = {node.getTypeKind().getPrintableName(),
|
||||
node.getImage(),
|
||||
" total",
|
||||
classWmc + " (highest " + classHighest + ")", };
|
||||
@ -143,13 +141,8 @@ public class CyclomaticComplexityRule extends AbstractJavaMetricsRule {
|
||||
|
||||
int cyclo = (int) JavaMetrics.get(JavaOperationMetricKey.CYCLO, node, cycloOptions);
|
||||
if (cyclo >= methodReportLevel) {
|
||||
String nodeType = node.getKind() == MethodLikeKind.METHOD
|
||||
? "method"
|
||||
: node.getKind() == MethodLikeKind.CONSTRUCTOR
|
||||
? "constructor"
|
||||
: "lambda";
|
||||
|
||||
addViolation(data, node, new String[]{nodeType,
|
||||
addViolation(data, node, new String[]{node.getKind().getPrintableName(),
|
||||
node.getQualifiedName().getOperation(),
|
||||
"",
|
||||
"" + cyclo, });
|
||||
|
@ -745,9 +745,6 @@ public class SecureSystem {
|
||||
<description>
|
||||
Annotating overridden methods with @Override ensures at compile time that
|
||||
the method really overrides one, which helps refactoring and clarifies intent.
|
||||
|
||||
This rule is limited to resolving methods inherited from non-parameterized
|
||||
or raw supertypes.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
|
@ -198,9 +198,35 @@ public void bar() {
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#avoidthrowingnullpointerexception">
|
||||
<description>
|
||||
Avoid throwing NullPointerExceptions. These are confusing because most people will assume that the
|
||||
virtual machine threw it. Consider using an IllegalArgumentException instead; this will be
|
||||
clearly seen as a programmer-initiated exception.
|
||||
<![CDATA[
|
||||
Avoid throwing NullPointerExceptions manually. These are confusing because most people will assume that the
|
||||
virtual machine threw it. To avoid a method being called with a null parameter, you may consider
|
||||
using an IllegalArgumentException instead, making it clearly seen as a programmer-initiated exception.
|
||||
However, there are better ways to handle this:
|
||||
|
||||
>*Effective Java, 3rd Edition, Item 72: Favor the use of standard exceptions*
|
||||
>
|
||||
>Arguably, every erroneous method invocation boils down to an illegal argument or state,
|
||||
but other exceptions are standardly used for certain kinds of illegal arguments and states.
|
||||
If a caller passes null in some parameter for which null values are prohibited, convention dictates that
|
||||
NullPointerException be thrown rather than IllegalArgumentException.
|
||||
|
||||
To implement that, you are encouraged to use `java.util.Objects.requireNonNull()`
|
||||
(introduced in Java 1.7). This method is designed primarily for doing parameter
|
||||
validation in methods and constructors with multiple parameters.
|
||||
|
||||
Your parameter validation could thus look like the following:
|
||||
```
|
||||
public class Foo {
|
||||
private String exampleValue;
|
||||
|
||||
void setExampleValue(String exampleValue) {
|
||||
// check, throw and assignment in a single standard call
|
||||
this.exampleValue = Objects.requireNonNull(exampleValue, "exampleValue must not be null!");
|
||||
}
|
||||
}
|
||||
```
|
||||
]]>
|
||||
</description>
|
||||
<priority>1</priority>
|
||||
<properties>
|
||||
|
@ -11,8 +11,10 @@
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
<java.version>8</java.version>
|
||||
<!-- Workaround for https://youtrack.jetbrains.com/issue/IDEA-188690 -->
|
||||
<maven.compiler.source>1.${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>1.${java.version}</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
@ -10,10 +10,6 @@
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
|
@ -10,10 +10,6 @@
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user