[doc] [java] Adjust externalInfoUrl properties to new site - Part 2
Note: I also took the chance to fix tab damage
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -9,12 +9,12 @@
|
||||
These rules deal with different problems that can occur with finalizers.
|
||||
</description>
|
||||
|
||||
<rule name="EmptyFinalizer"
|
||||
language="java"
|
||||
since="1.5"
|
||||
message="Avoid empty finalize methods"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/finalizers.html#EmptyFinalizer">
|
||||
<rule name="EmptyFinalizer"
|
||||
language="java"
|
||||
since="1.5"
|
||||
message="Avoid empty finalize methods"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_finalizers.html#emptyfinalizer">
|
||||
<description>
|
||||
Empty finalize methods serve no purpose and should be removed.
|
||||
</description>
|
||||
@ -38,12 +38,12 @@ public class Foo {
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="FinalizeOnlyCallsSuperFinalize"
|
||||
language="java"
|
||||
since="1.5"
|
||||
message="Finalize should do something besides just calling super.finalize()"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/finalizers.html#FinalizeOnlyCallsSuperFinalize">
|
||||
<rule name="FinalizeOnlyCallsSuperFinalize"
|
||||
language="java"
|
||||
since="1.5"
|
||||
message="Finalize should do something besides just calling super.finalize()"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_finalizers.html#finalizeonlycallssuperfinalize">
|
||||
<description>
|
||||
If the finalize() is implemented, it should do something besides just calling super.finalize().
|
||||
</description>
|
||||
@ -66,18 +66,18 @@ If the finalize() is implemented, it should do something besides just calling su
|
||||
<example>
|
||||
<![CDATA[
|
||||
protected void finalize() {
|
||||
super.finalize();
|
||||
super.finalize();
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="FinalizeOverloaded"
|
||||
language="java"
|
||||
since="1.5"
|
||||
message="Finalize methods should not be overloaded"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/finalizers.html#FinalizeOverloaded">
|
||||
<rule name="FinalizeOverloaded"
|
||||
language="java"
|
||||
since="1.5"
|
||||
message="Finalize methods should not be overloaded"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_finalizers.html#finalizeoverloaded">
|
||||
<description>
|
||||
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.
|
||||
@ -96,20 +96,20 @@ overload Object.finalize(). It will not be called by the VM.
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
// this is confusing and probably a bug
|
||||
protected void finalize(int a) {
|
||||
}
|
||||
// this is confusing and probably a bug
|
||||
protected void finalize(int a) {
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="FinalizeDoesNotCallSuperFinalize"
|
||||
language="java"
|
||||
since="1.5"
|
||||
message="Last statement in finalize method should be a call to super.finalize()"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/finalizers.html#FinalizeDoesNotCallSuperFinalize">
|
||||
<rule name="FinalizeDoesNotCallSuperFinalize"
|
||||
language="java"
|
||||
since="1.5"
|
||||
message="Last statement in finalize method should be a call to super.finalize()"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_finalizers.html#finalizedoesnotcallsuperfinalize">
|
||||
<description>
|
||||
If the finalize() is implemented, its last action should be to call super.finalize.
|
||||
</description>
|
||||
@ -117,7 +117,7 @@ If the finalize() is implemented, its last action should be to call super.finali
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<!-- in english: a method declaration of finalize(), with no arguments, containing
|
||||
<!-- in English: a method declaration of finalize(), with no arguments, containing
|
||||
a block whose last statement is NOT a call to super.finalize -->
|
||||
<![CDATA[
|
||||
//MethodDeclaration[MethodDeclarator[@Image='finalize'][not(FormalParameters/*)]]
|
||||
@ -141,19 +141,19 @@ a block whose last statement is NOT a call to super.finalize -->
|
||||
<example>
|
||||
<![CDATA[
|
||||
protected void finalize() {
|
||||
something();
|
||||
// neglected to call super.finalize()
|
||||
something();
|
||||
// neglected to call super.finalize()
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="FinalizeShouldBeProtected"
|
||||
language="java"
|
||||
since="1.1"
|
||||
message="If you override finalize(), make it protected"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/finalizers.html#FinalizeShouldBeProtected">
|
||||
<rule name="FinalizeShouldBeProtected"
|
||||
language="java"
|
||||
since="1.1"
|
||||
message="If you override finalize(), make it protected"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_finalizers.html#finalizeshouldbeprotected">
|
||||
<description>
|
||||
When overriding the finalize(), the new method should be set as protected. If made public,
|
||||
other classes may invoke it at inappropriate times.
|
||||
@ -173,17 +173,17 @@ other classes may invoke it at inappropriate times.
|
||||
<example>
|
||||
<![CDATA[
|
||||
public void finalize() {
|
||||
// do something
|
||||
// do something
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="AvoidCallingFinalize"
|
||||
since="3.0"
|
||||
message="Avoid calling finalize() explicitly"
|
||||
class="net.sourceforge.pmd.lang.java.rule.finalizers.AvoidCallingFinalizeRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/finalizers.html#AvoidCallingFinalize">
|
||||
<rule name="AvoidCallingFinalize"
|
||||
since="3.0"
|
||||
message="Avoid calling finalize() explicitly"
|
||||
class="net.sourceforge.pmd.lang.java.rule.finalizers.AvoidCallingFinalizeRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_finalizers.html#avoidcallingfinalize">
|
||||
<description>
|
||||
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.
|
||||
@ -192,8 +192,8 @@ that there are no more references to the object. It should not be invoked by app
|
||||
<example>
|
||||
<![CDATA[
|
||||
void foo() {
|
||||
Bar b = new Bar();
|
||||
b.finalize();
|
||||
Bar b = new Bar();
|
||||
b.finalize();
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
|
@ -10,10 +10,10 @@ These rules deal with different problems that can occur with import statements.
|
||||
</description>
|
||||
|
||||
<rule name="DuplicateImports"
|
||||
since="0.5"
|
||||
since="0.5"
|
||||
message="Avoid duplicate imports such as ''{0}''"
|
||||
class="net.sourceforge.pmd.lang.java.rule.imports.DuplicateImportsRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/imports.html#DuplicateImports">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_imports.html#duplicateimports">
|
||||
<description>
|
||||
Duplicate or overlapping import statements should be avoided.
|
||||
</description>
|
||||
@ -28,23 +28,23 @@ public class Foo {}
|
||||
</rule>
|
||||
|
||||
<rule name="DontImportJavaLang"
|
||||
since="0.5"
|
||||
since="0.5"
|
||||
message="Avoid importing anything from the package 'java.lang'"
|
||||
class="net.sourceforge.pmd.lang.java.rule.imports.DontImportJavaLangRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/imports.html#DontImportJavaLang">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_imports.html#dontimportjavalang">
|
||||
<description>
|
||||
Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3).
|
||||
</description>
|
||||
<priority>4</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
import java.lang.String; // this is unnecessary
|
||||
import java.lang.String; // this is unnecessary
|
||||
|
||||
public class Foo {}
|
||||
|
||||
// --- in another source code file...
|
||||
|
||||
import java.lang.*; // this is bad
|
||||
import java.lang.*; // this is bad
|
||||
|
||||
public class Foo {}
|
||||
]]>
|
||||
@ -52,10 +52,10 @@ public class Foo {}
|
||||
</rule>
|
||||
|
||||
<rule name="UnusedImports"
|
||||
since="1.0"
|
||||
since="1.0"
|
||||
message="Avoid unused imports such as ''{0}''"
|
||||
class="net.sourceforge.pmd.lang.java.rule.imports.UnusedImportsRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/imports.html#UnusedImports">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_imports.html#unusedimports">
|
||||
<description>
|
||||
Avoid the use of unused import statements to prevent unwanted dependencies.
|
||||
</description>
|
||||
@ -69,77 +69,77 @@ public class Foo {}
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ImportFromSamePackage"
|
||||
since="1.02"
|
||||
message="No need to import a type that lives in the same package"
|
||||
class="net.sourceforge.pmd.lang.java.rule.imports.ImportFromSamePackageRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/imports.html#ImportFromSamePackage">
|
||||
<rule name="ImportFromSamePackage"
|
||||
since="1.02"
|
||||
message="No need to import a type that lives in the same package"
|
||||
class="net.sourceforge.pmd.lang.java.rule.imports.ImportFromSamePackageRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_imports.html#importfromsamepackage">
|
||||
<description>
|
||||
There is no need to import a type that lives in the same package.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
package foo;
|
||||
|
||||
import foo.Buz; // no need for this
|
||||
import foo.*; // or this
|
||||
|
||||
public class Bar{}
|
||||
]]>
|
||||
package foo;
|
||||
|
||||
import foo.Buz; // no need for this
|
||||
import foo.*; // or this
|
||||
|
||||
public class Bar{}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="TooManyStaticImports"
|
||||
language="java"
|
||||
since="4.1"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
message="Too many static imports may lead to messy code"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/imports.html#TooManyStaticImports">
|
||||
<description><![CDATA[
|
||||
<rule name="TooManyStaticImports"
|
||||
language="java"
|
||||
since="4.1"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
message="Too many static imports may lead to messy code"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_imports.html#toomanystaticimports">
|
||||
<description>
|
||||
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).
|
||||
]]></description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="maximumStaticImports" type="Integer"
|
||||
description="All static imports can be disallowed by setting this to 0" min="0" max="100" value="4"/>
|
||||
<property name="xpath">
|
||||
<value><![CDATA[
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="maximumStaticImports" type="Integer"
|
||||
description="All static imports can be disallowed by setting this to 0" min="0" max="100" value="4"/>
|
||||
<property name="xpath">
|
||||
<value><![CDATA[
|
||||
.[count(ImportDeclaration[@Static = 'true']) > $maximumStaticImports]
|
||||
]]></value>
|
||||
</property>
|
||||
</properties>
|
||||
<example><![CDATA[
|
||||
]]></value>
|
||||
</property>
|
||||
</properties>
|
||||
<example><![CDATA[
|
||||
import static Lennon;
|
||||
import static Ringo;
|
||||
import static George;
|
||||
import static Paul;
|
||||
import static Yoko; // Too much !
|
||||
]]></example>
|
||||
</rule>
|
||||
|
||||
<rule name="UnnecessaryFullyQualifiedName"
|
||||
language="java"
|
||||
since="5.0"
|
||||
class="net.sourceforge.pmd.lang.java.rule.imports.UnnecessaryFullyQualifiedNameRule"
|
||||
message="Unnecessary use of fully qualified name ''{0}'' due to existing {2}import ''{1}''"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/imports.html#UnnecessaryFullyQualifiedName">
|
||||
<description><![CDATA[
|
||||
]]></example>
|
||||
</rule>
|
||||
|
||||
<rule name="UnnecessaryFullyQualifiedName"
|
||||
language="java"
|
||||
since="5.0"
|
||||
class="net.sourceforge.pmd.lang.java.rule.imports.UnnecessaryFullyQualifiedNameRule"
|
||||
message="Unnecessary use of fully qualified name ''{0}'' due to existing {2}import ''{1}''"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_imports.html#unnecessaryfullyqualifiedname">
|
||||
<description>
|
||||
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.
|
||||
]]></description>
|
||||
<priority>4</priority>
|
||||
<example><![CDATA[
|
||||
</description>
|
||||
<priority>4</priority>
|
||||
<example><![CDATA[
|
||||
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'
|
||||
private java.util.List list1; // Unnecessary FQN
|
||||
private List list2; // More appropriate given import of 'java.util.List'
|
||||
}
|
||||
]]></example>
|
||||
</rule>
|
||||
]]></example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -11,17 +11,17 @@ The JavaBeans Ruleset catches instances of bean rules not being followed.
|
||||
|
||||
|
||||
<rule name="BeanMembersShouldSerialize"
|
||||
since="1.1"
|
||||
since="1.1"
|
||||
message="Found non-transient, non-static member. Please mark as transient or provide accessors."
|
||||
class="net.sourceforge.pmd.lang.java.rule.javabeans.BeanMembersShouldSerializeRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/javabeans.html#BeanMembersShouldSerialize">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_javabeans.html#beanmembersshouldserialize">
|
||||
<description>
|
||||
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.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
private transient int someFoo; // good, it's transient
|
||||
@ -41,12 +41,12 @@ private int getMoreFoo(){
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="MissingSerialVersionUID"
|
||||
language="java"
|
||||
since="3.0"
|
||||
message="Classes implementing Serializable should set a serialVersionUID"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/javabeans.html#MissingSerialVersionUID">
|
||||
<rule name="MissingSerialVersionUID"
|
||||
language="java"
|
||||
since="3.0"
|
||||
message="Classes implementing Serializable should set a serialVersionUID"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_javabeans.html#missingserialversionuid">
|
||||
<description>
|
||||
Serializable classes should provide a serialVersionUID field.
|
||||
</description>
|
||||
@ -73,13 +73,12 @@ and
|
||||
<example>
|
||||
<![CDATA[
|
||||
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;
|
||||
String name;
|
||||
// Define serialization id to avoid serialization related bugs
|
||||
// i.e., public static final long serialVersionUID = 4328743;
|
||||
}
|
||||
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -8,19 +8,19 @@
|
||||
The Jakarta Commons Logging ruleset contains a collection of rules that find questionable usages of that framework.
|
||||
</description>
|
||||
|
||||
<rule name="UseCorrectExceptionLogging"
|
||||
language="java"
|
||||
since="3.2"
|
||||
<rule name="UseCorrectExceptionLogging"
|
||||
language="java"
|
||||
since="3.2"
|
||||
message="Use the correct logging statement for logging exceptions"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/logging-jakarta-commons.html#UseCorrectExceptionLogging">
|
||||
<description>
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_logging-jakarta-commons.html#usecorrectexceptionlogging">
|
||||
<description>
|
||||
To make sure the full stacktrace is printed out, use the logging statement with two arguments: a String and a Throwable.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value><![CDATA[
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value><![CDATA[
|
||||
//CatchStatement/Block/BlockStatement/Statement/StatementExpression
|
||||
/PrimaryExpression[PrimaryPrefix/Name[starts-with(@Image,
|
||||
concat(ancestor::ClassOrInterfaceDeclaration/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration
|
||||
@ -28,40 +28,39 @@ concat(ancestor::ClassOrInterfaceDeclaration/ClassOrInterfaceBody/ClassOrInterfa
|
||||
/VariableDeclarator/VariableDeclaratorId/@Image, '.'))]]
|
||||
[PrimarySuffix/Arguments[@ArgumentCount='1']]
|
||||
[PrimarySuffix/Arguments//Name/@Image = ancestor::CatchStatement/FormalParameter/VariableDeclaratorId/@Image]
|
||||
]]></value>
|
||||
</property>
|
||||
</properties>
|
||||
<example><![CDATA[
|
||||
]]></value>
|
||||
</property>
|
||||
</properties>
|
||||
<example><![CDATA[
|
||||
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
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></example>
|
||||
</rule>
|
||||
</rule>
|
||||
|
||||
<rule name="ProperLogger"
|
||||
language="java"
|
||||
since="3.3"
|
||||
message="Logger should be defined private static final and have the correct class"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/logging-jakarta-commons.html#ProperLogger">
|
||||
<description>
|
||||
<rule name="ProperLogger"
|
||||
language="java"
|
||||
since="3.3"
|
||||
message="Logger should be defined private static final and have the correct class"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_logging-jakarta-commons.html#properlogger">
|
||||
<description>
|
||||
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.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value><![CDATA[
|
||||
//ClassOrInterfaceBodyDeclaration[FieldDeclaration//ClassOrInterfaceType[@Image='Log']
|
||||
and
|
||||
not(FieldDeclaration[@Final='true'][@Static='true'][@Private='true'][.//VariableDeclaratorId[@Image=$staticLoggerName]]
|
||||
@ -71,36 +70,35 @@ with the restriction that the logger needs to be passed into the constructor.
|
||||
[count(.//VariableInitializer)=0]
|
||||
[ancestor::ClassOrInterfaceBody//StatementExpression[.//PrimaryExpression/descendant::*[@Image='log']][count(.//AllocationExpression)=0]]
|
||||
)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
<property name="staticLoggerName" type="String" description="Name of the static Logger variable" value="LOG"/>
|
||||
</properties>
|
||||
<example>
|
||||
]]></value>
|
||||
</property>
|
||||
<property name="staticLoggerName" type="String" description="Name of the static Logger variable" value="LOG"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(Foo.class); // proper way
|
||||
private static final Log LOG = LogFactory.getLog(Foo.class); // proper way
|
||||
|
||||
protected Log LOG = LogFactory.getLog(Testclass.class); // wrong approach
|
||||
protected Log LOG = LogFactory.getLog(Testclass.class); // wrong approach
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="GuardDebugLogging"
|
||||
language="java"
|
||||
since="4.3"
|
||||
message="debug logging that involves string concatenation should be guarded with isDebugEnabled() checks"
|
||||
class="net.sourceforge.pmd.lang.java.rule.logging.GuardDebugLoggingRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/logging-jakarta-commons.html#GuardDebugLogging">
|
||||
<description>
|
||||
When log messages are composed by concatenating strings, the whole section should be guarded
|
||||
by a isDebugEnabled() check to avoid performance and memory issues.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
<rule name="GuardDebugLogging"
|
||||
language="java"
|
||||
since="4.3"
|
||||
message="debug logging that involves string concatenation should be guarded with isDebugEnabled() checks"
|
||||
class="net.sourceforge.pmd.lang.java.rule.logging.GuardDebugLoggingRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_logging-jakarta-commons.html#guarddebuglogging">
|
||||
<description>
|
||||
When log messages are composed by concatenating strings, the whole section should be guarded
|
||||
by a isDebugEnabled() check to avoid performance and memory issues.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Test {
|
||||
private static final Log __log = LogFactory.getLog(Test.class);
|
||||
public void test() {
|
||||
@ -123,27 +121,27 @@ public class Test {
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="GuardLogStatement"
|
||||
language="java"
|
||||
since="5.1.0"
|
||||
message="There is log block not surrounded by if"
|
||||
class="net.sourceforge.pmd.lang.java.rule.logging.GuardLogStatementRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/logging-jakarta-commons.html#GuardLogStatement">
|
||||
<description>
|
||||
<rule name="GuardLogStatement"
|
||||
language="java"
|
||||
since="5.1.0"
|
||||
message="There is log block not surrounded by if"
|
||||
class="net.sourceforge.pmd.lang.java.rule.logging.GuardLogStatementRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_logging-jakarta-commons.html#guardlogstatement">
|
||||
<description>
|
||||
Whenever using a log level, one should check if the loglevel is actually enabled, or
|
||||
otherwise skip the associate String creation and manipulation.
|
||||
</description>
|
||||
<priority>2</priority>
|
||||
<example>
|
||||
</description>
|
||||
<priority>2</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
// Add this for performance
|
||||
if (log.isDebugEnabled() { ...
|
||||
log.debug("log something" + " and " + "concat strings");
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
@ -9,16 +9,16 @@
|
||||
The Java Logging ruleset contains a collection of rules that find questionable usages of the logger.
|
||||
</description>
|
||||
|
||||
<rule name="MoreThanOneLogger"
|
||||
since="2.0"
|
||||
message="Class contains more than one logger."
|
||||
class="net.sourceforge.pmd.lang.java.rule.logging.MoreThanOneLoggerRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/logging-java.html#MoreThanOneLogger">
|
||||
<description>
|
||||
<rule name="MoreThanOneLogger"
|
||||
since="2.0"
|
||||
message="Class contains more than one logger."
|
||||
class="net.sourceforge.pmd.lang.java.rule.logging.MoreThanOneLoggerRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_logging-java.html#morethanonelogger">
|
||||
<description>
|
||||
Normally only one logger is used in each class.
|
||||
</description>
|
||||
<priority>2</priority>
|
||||
<example>
|
||||
</description>
|
||||
<priority>2</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
Logger log = Logger.getLogger(Foo.class.getName());
|
||||
@ -27,15 +27,15 @@ public class Foo {
|
||||
Logger log2= Logger.getLogger(Foo.class.getName());
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="LoggerIsNotStaticFinal"
|
||||
language="java"
|
||||
since="2.0"
|
||||
message="The Logger variable declaration does not contain the static and final modifiers"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/logging-java.html#LoggerIsNotStaticFinal">
|
||||
<rule name="LoggerIsNotStaticFinal"
|
||||
language="java"
|
||||
since="2.0"
|
||||
message="The Logger variable declaration does not contain the static and final modifiers"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_logging-java.html#loggerisnotstaticfinal">
|
||||
<description>
|
||||
In most cases, the Logger reference can be declared as static and final.
|
||||
</description>
|
||||
@ -57,20 +57,20 @@ In most cases, the Logger reference can be declared as static and final.
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo{
|
||||
Logger log = Logger.getLogger(Foo.class.getName()); // not recommended
|
||||
Logger log = Logger.getLogger(Foo.class.getName()); // not recommended
|
||||
|
||||
static final Logger log = Logger.getLogger(Foo.class.getName()); // preferred approach
|
||||
static final Logger log = Logger.getLogger(Foo.class.getName()); // preferred approach
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="SystemPrintln"
|
||||
language="java"
|
||||
since="2.1"
|
||||
message="{0} is used"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/logging-java.html#SystemPrintln">
|
||||
<rule name="SystemPrintln"
|
||||
language="java"
|
||||
since="2.1"
|
||||
message="{0} is used"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_logging-java.html#systemprintln">
|
||||
<description>
|
||||
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
|
||||
@ -101,81 +101,84 @@ class Foo{
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="AvoidPrintStackTrace"
|
||||
language="java"
|
||||
since="3.2"
|
||||
message="Avoid printStackTrace(); use a logger call instead."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/logging-java.html#AvoidPrintStackTrace">
|
||||
<description>
|
||||
<rule name="AvoidPrintStackTrace"
|
||||
language="java"
|
||||
since="3.2"
|
||||
message="Avoid printStackTrace(); use a logger call instead."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_logging-java.html#avoidprintstacktrace">
|
||||
<description>
|
||||
Avoid printStackTrace(); use a logger call instead.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//PrimaryExpression
|
||||
[PrimaryPrefix/Name[contains(@Image,'printStackTrace')]]
|
||||
[PrimarySuffix[not(boolean(Arguments/ArgumentList/Expression))]]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
class Foo {
|
||||
void bar() {
|
||||
try {
|
||||
// do something
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
void bar() {
|
||||
try {
|
||||
// do something
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="GuardLogStatementJavaUtil"
|
||||
language="java"
|
||||
since="5.1.0"
|
||||
message="There is log block not surrounded by if"
|
||||
class="net.sourceforge.pmd.lang.java.rule.logging.GuardLogStatementJavaUtilRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/logging-java.html#GuardLogStatementJavaUtil">
|
||||
<description>
|
||||
<rule name="GuardLogStatementJavaUtil"
|
||||
language="java"
|
||||
since="5.1.0"
|
||||
message="There is log block not surrounded by if"
|
||||
class="net.sourceforge.pmd.lang.java.rule.logging.GuardLogStatementJavaUtilRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_logging-java.html#guardlogstatementjavautil">
|
||||
<description>
|
||||
Whenever using a log level, one should check if the loglevel is actually enabled, or
|
||||
otherwise skip the associate String creation and manipulation.
|
||||
</description>
|
||||
<priority>2</priority>
|
||||
<example>
|
||||
</description>
|
||||
<priority>2</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
// Add this for performance
|
||||
if (log.isLoggable(Level.FINE)) { ...
|
||||
log.fine("log something" + " and " + "concat strings");
|
||||
//...
|
||||
// Add this for performance
|
||||
if (log.isLoggable(Level.FINE)) {
|
||||
log.fine("log something" + " and " + "concat strings");
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="InvalidSlf4jMessageFormat"
|
||||
language="java"
|
||||
since="5.5.0"
|
||||
message="Invalid message format"
|
||||
class="net.sourceforge.pmd.lang.java.rule.logging.InvalidSlf4jMessageFormatRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/logging-java.html#InvalidSlf4jMessageFormat">
|
||||
<description>
|
||||
<rule name="InvalidSlf4jMessageFormat"
|
||||
language="java"
|
||||
since="5.5.0"
|
||||
message="Invalid message format"
|
||||
class="net.sourceforge.pmd.lang.java.rule.logging.InvalidSlf4jMessageFormatRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_logging-java.html#invalidslf4jmessageformat">
|
||||
<description>
|
||||
Check for messages in slf4j loggers with non matching number of arguments and placeholders.
|
||||
</description>
|
||||
<priority>5</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
</description>
|
||||
<priority>5</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
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.
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
Reference in New Issue
Block a user