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