All Downloads are FREE. Search and download functionalities are using the official Maven repository.

resources.report.rules.pmd.StaticEJBFieldShouldBeFinal.html Maven / Gradle / Ivy



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
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy