Branch: refs/heads/main
Home: https://github.com/pmd/pmd
Commit: 89b473e632fb40952c59b943d543f7b8ec801dc5
https://github.com/pmd/pmd/commit/89b473e632fb40952c59b943d543f7b8ec801dc5
Author: fudian <[email protected]>
Date: 2026-08-20 (Thu, 20 Aug 2026)
Changed paths:
M docs/pages/release_notes.md
M pmd-java/src/main/resources/category/java/errorprone.xml
M
pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/StaticEJBFieldShouldBeFinal.xml
Log Message:
-----------
[java] Fix #6537: StaticEJBFieldShouldBeFinal detects
@Stateless/@Stateful/@Singleton/@MessageDriven EJB classes (#6945)
* [java] Fix #6537: StaticEJBFieldShouldBeFinal detects
@Stateless/@Stateful/@Singleton/@MessageDriven EJB classes
The rule only matched classes implementing one of the five javax.ejb
interfaces (SessionBean, EJBHome, EJBLocalObject, EJBLocalHome, EJBObject),
causing a false negative for EJB component classes declared via the
@Stateless/@Stateful/@Singleton/@MessageDriven annotations, which is the
canonical way to declare enterprise beans since EJB 3.0.
Root cause: the XPath predicate only inspected the ImplementsList and ignored
the modifier annotations. We add an annotation-based branch using
pmd-java:hasAnnotation for both the javax.ejb and jakarta.ejb namespaces
(jakarta replaces javax in Jakarta EE 9+).
hasAnnotation is preferred over matching the annotation simple name, as the
latter would also match unrelated annotations sharing the same simple name,
e.g. javax.inject.Singleton (CDI), which is out of scope for this rule.
@MessageDriven (message-driven beans) is included as well: the EJB "no
read/write static fields" programming restriction applies to message-driven
beans just as it does to session beans, so leaving them out would keep the
rule inconsistent (flagging session beans but not MDBs). The ImplementsList
branch is left untouched, so EJB 2.x style declarations are still detected.
Test cases cover @Stateless/@Stateful (javax.ejb), @Singleton (jakarta.ejb),
@MessageDriven (both javax.ejb and jakarta.ejb), a negative case with
final/instance fields, and a negative case ensuring javax.inject.Singleton
(CDI) is not flagged.
Signed-off-by: 付典 <[email protected]>
* correct ticket name in release notes
---------
Signed-off-by: 付典 <[email protected]>
Co-authored-by: Sören Glimm <[email protected]>
To unsubscribe from these emails, change your notification settings at
https://github.com/pmd/pmd/settings/notifications
_______________________________________________
Pmd-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pmd-commits