java:S3305 don't report field if bean creation method is used i multiple places

Thanks for your great work.

This is about java:S3305:

Noncompliant Code Example
  @Configuration
  public class ​FooConfiguration {
      @Autowired private ​DataSource dataSource​; // Noncompliant

      @Bean    public ​MyService myService() {
      return new ​MyService(this​.dataSource​);
    }
  }  

It makes total sense to move the Autowired field into the bean method. However, there is one exception I’d like to see added: If myService() is used in one or more other bean method:

      @Bean    public ​MyOtherService myOtherService() {
      return new ​MyOtherService(myService()​); // don't report "field only used in myService" because then I'd have to declare the Autowired in myOtherService as well.
    }

Hope the idea is clear,

Best,

Jan

Hey @Jan47

Please read this thread regarding reporting false-positives:

(We’re missing what product you’re using and what version if applicable)