[squid:S3749] Should consider @PersistenceContext a valid injection

  • SonarQube 7.3
  • squid:S3749 (Members of Spring components should be injected) doesn’t recognize @PersistenceContext (from javax.persistence) as an auto-injection
  • Have a @Repository class with a member variable annotated with @PersistenceContext. Variable gets flagged as a violation of this rule.
  • Workaround: Use the customInjectionAnnotations parameter of this rule to add javax.persistence.PersistenceContext as a valid annotation.

Sample:

@Repository
class MyRepo
{
    @PersistenceContext
    private EntityManager em; // This line gets tagged with the rule

Hey,

Sorry @KC_Baltz for the veeeeeery long time before answering you. This thread went completely out of our radar.
I just created the following ticket to handle it: SONARJAVA-3499

Note that the fix is currently planned for version 6.7 of our Java analyzer, which will be available only on SonarCloud and SonarQube 8.5 (expected to be released at the end of September). For LTS users, it won’t be possible to benefit from it.

However, as tested on my local SQ instance, a possible workaround is to configure the rule by settings its customInjectionAnnotations parameter with javax.persistence.PersistenceContext, which will make the issue disappear.

Cheers,
Michael

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.