Rule Definition
An enterprise bean must not use read/write static fields. Using read-only static fields is allowed. Therefore, it is recommended that all static fields in the enterprise bean class be declared as final.
This rule is required to ensure consistent runtime semantics because while some EJB containers may use a single JVM to execute all enterprise bean's instances, others may distribute the instances across
multiple JVMs.
Remediation
Declare these static fields as final or review your design.
Violation Code Sample
@Stateful
public class MyBean implements MyRemoteBean {
private static String myName = "MyBean"; // VIOLATION
...
public int aMethod() {
...
}
...
}
Fixed Code Sample
@Stateful
public class MyBean implements MyRemoteBean {
private static final String myName = "MyBean"; // FIXED
...
public int aMethod() {
...
}
...
}
Reference
JSR-220 Enterprise Java Beans 3.0 Final Release (ejbcore) page 545
Related Technologies
JEE
Technical Criterion
Programming Practices - Modularity and OO Encapsulation Conformity
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.