SonarQube detects the issue “Members of Spring components should be injected (java:S3749)” for the code below.
According to the rule, both private fields should be annotated with (e.g. with @Autowired).
Though this isn’t necessary, as we are getting the constructor generated by lombok.
Weird: When I use @Component instead of @Service, the issues disappear.
Can someone help me to decide if this is a true positive, a bug in SonarJava or if the code could be written in another way?
Best Regards,
Matthias
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
@Slf4j
@Service
@Transactional
@AllArgsConstructor
public class EnpFacade {
private final EnpRepository enpRepository;
private final DateTimeProvider dateTimeProvider;
// methods ....
It was indeed a false positive, I let you have a look there for the details.
For information, both tickets created are already fixed.
As a side note, reporting the issue here was a good move (thanks again for that!), however, I would not advise using a workaround when facing false positive, but to resolve it as false positive/won’t fix.