Repository navigation
Description
Rule: StaticEJBFieldShouldBeFinal
False Negative: Mutable static EJB fields are not recognized across declaration variants.
Version
7.22.0
Checker
- Checker id:
category/java/errorprone.xml/StaticEJBFieldShouldBeFinal - Checker description: This checker detects static field declarations in EJB-related classes that are not declared final.
Description of the false negative
diff/output marks 1 false negatives for category/java/errorprone.xml/StaticEJBFieldShouldBeFinal. Across these samples, the benchmark is still exercising the same underlying bug pattern, but the implementation appears to lose track of it once the source deviates from one canonical shape. The recurring themes are suppression or annotations.
Affected test cases
PosCase1.java
Source: output/codeql/EjbStaticFieldNonFinal/src/main/java/scensct/core/pos/PosCase1.java
The sample keeps the benchmark's target pattern but expresses it in a slightly non-canonical source form. The risky pattern is still present in the code, so the absence of a report points to a matching gap rather than a benign variant. That is also how the benchmark classifies the sample: An EJB component accesses a non-final static field via a method call should be flagged as violation.
// An EJB component accesses a non-final static field via a method call should be flagged as violation.
package scensct.core.pos;
import javax.ejb.Stateless;
@Stateless
public class PosCase1 {
private static int nonFinalStatic = 0; // Non-final static field
public void targetMethod() {
int value = nonFinalStatic; // Accessing non-final static field
}
public void ejbBusinessMethod() { // [REPORTED LINE]
targetMethod(); // Calling the method that accesses the static field
}
}Cause analysis
The rule is documented as follows: This checker detects static field declarations in EJB-related classes that are not declared final.
In this set the problem shows up around suppression or annotations. The missed cases suggest that the implementation is narrower than the rule description and too dependent on one preferred AST shape.
Once the same behavior is expressed through a helper, an overload, a modifier such as abstract or native, a different comment position, or a slightly rearranged control-flow structure, the report disappears even though the benchmark still treats the case as in-scope.
For category/java/errorprone.xml/StaticEJBFieldShouldBeFinal, the practical improvement would be to generalize the match so it follows the underlying behavior rather than one exact spelling of it.
References
None known.
Activity
zbynek commentedon Mar 25, 2026
I guess the issue you're actually trying to describe is that classes annotated
javax.ejb.Statelessshould be considered components, while the rule currently only considers classes implementing one of five interfaces.I'm not sure if that's needed, but the rule should be definitely updated to support
jakartaalong withjavaxpackages.[-]False Negative: Mutable static EJB fields are not recognized across declaration variants.[/-][+][java] False Negative: Mutable static EJB fields are not recognized across declaration variants.[/+][java] Fix pmd#6537: StaticEJBFieldShouldBeFinal detects @Stateless/@…
[java] Fix pmd#6537: StaticEJBFieldShouldBeFinal detects @Stateless/@…
[java] Fix pmd#6537: StaticEJBFieldShouldBeFinal detects @Stateless/@…
[-][java] False Negative: Mutable static EJB fields are not recognized across declaration variants.[/-][+][java] StaticEJBFieldShouldBeFinal: False Negative when using @Stateless etc.[/+][java] Fix #6537: StaticEJBFieldShouldBeFinal detects @Stateless/@Sta…