False positive on java:S3749 with PersistentContext decorator

Hello everyone,

I would like to report a potential false positive for java:S3749 rule.

  • What language is this for? Java
  • Which rule? java:S3749
  • SonarQube v9.9.5

Why do you believe it’s a false-positive/false-negative?

Rule S3749 mentions that “all non-static members should be managed by Spring. That is, they should have one of these annotations: @Resource , @Inject , @Autowired or @Value”, however the PersistenceContext takes care to create a unique EntityManager for every transaction (communication with the database).

We then think that the issue may be a false positive in this particular case. Here is an example of code that will be flagged :

package com.example;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ExampleDao {
  @PersistenceContext
  private EntityManager entityManager;
  // Rest of the code using entityManager ...
}

Thanks in advance for your help,
Thibault

Hi @S0obi,

In the current SonarQube LTA version 9.9, this rule does not support Jakarta annotations yet, but only the old javax annotations. This issue is fixed in our latest SonarQube version.

Best,
Marco

Thanks @Marco_Kaufmann, we will then patiently wait for the next LTA to be released :slight_smile:

Thibault

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