SONARJAVA-6540 Implement S8954: Bean Validation constraints should not be placed on static fields#5724
Conversation
Code Review 👍 Approved with suggestions 1 resolved / 2 findingsImplements rule S8954 to flag Bean Validation constraints on static fields, with support for both javax and jakarta packages. Heuristic container detection is functional, though note that nested annotation detection may occasionally cause false positives. 💡 Edge Case: Heuristic container detection may cause false positivesThe new logic infers that an annotation is a repeatable-constraint container whenever any of its argument values is (or contains, via an array/assignment) a nested annotation that is itself a Bean Validation constraint. This is a heuristic rather than an actual check for the container/ As a result, any non-container annotation that legitimately accepts a nested constraint annotation as a member value (e.g. a custom or framework annotation with a member of type A more precise approach is to verify that the outer annotation type is the container of a repeatable constraint — e.g. its ✅ 1 resolved✅ Edge Case: Repeatable/container constraint annotations are not detected
🤖 Prompt for agentsOptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
4f84482 to
7fb0576
Compare
romainbrenguier
left a comment
There was a problem hiding this comment.
The messaging doesn't look great to me. Otherwise implementation looks good.
|
Code Review ✅ Approved 2 resolved / 2 findingsImplements rule S8954 to flag Bean Validation constraints on static fields for both javax and jakarta namespaces. The final implementation resolves potential false positives from container heuristic detection and ensures accurate identification of constraint annotations. ✅ 2 resolved✅ Edge Case: Repeatable/container constraint annotations are not detected
✅ Edge Case: Heuristic container detection may cause false positives
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |




Summary by Gitar
BeanValidationConstraintOnStaticFieldCheckto flag constraints onstaticfields.javaxandjakartavalidation packages.S8954.jsonandS8954.htmlwith rule details and remediation guidance.Sonar_way_profile.jsonconfiguration.BeanValidationConstraintOnStaticFieldCheckTestusing provided sample files forjavaxandjakartavalidation.diff_S1710.jsonand addeddiff_S8954.jsonin theautoscantest resources.This will update automatically on new commits.