resources.report.rules.pmd.StaticEJBFieldShouldBeFinal.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sanity4j Show documentation
Show all versions of sanity4j Show documentation
Sanity4J was created to simplify running multiple static code
analysis tools on the Java projects. It provides a single entry
point to run all the selected tools and produce a consolidated
report, which presents all findings in an easily accessible
manner.
The newest version!
StaticEJBFieldShouldBeFinal
StaticEJBFieldShouldBeFinal
According to the J2EE specification, an EJB should not have any static fields with write access. However, static read-only fields are allowed. This ensures proper behavior especially when instances are distributed by the container on several JREs.
//ClassOrInterfaceDeclaration[
(
(./ImplementsList/ClassOrInterfaceType[ends-with(@Image,'SessionBean')])
or
(./ImplementsList/ClassOrInterfaceType[ends-with(@Image,'EJBHome')])
or
(./ImplementsList/ClassOrInterfaceType[ends-with(@Image,'EJBLocalObject')])
or
(./ImplementsList/ClassOrInterfaceType[ends-with(@Image,'EJBLocalHome')])
or
(./ExtendsList/ClassOrInterfaceType[ends-with(@Image,'EJBObject')])
)
and
(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration[
(./FieldDeclaration[@Static = 'true'])
and
(./FieldDeclaration[@Final = 'false'])
])
]
Example(s):
public class SomeEJB extends EJBObject implements EJBLocalHome {
private static int CountA; // poor, field can be edited
private static final int CountB; // preferred, read-only access
}