Java SpringBoot @Resource not detected

Hello the team,

I experimented this morning an issue with SpringBoot @Resource annotation.

Here are all the technical informations :

  • Language : Java SpringBoot
  • Rule : S3749
  • It’s a false positive
  • On Sonar Data Center Edition • v2025.3.1 (109879)

Here is the code detected as false positive

@Component
@Setter
public class MyBeautifulClass {
  
  // next line is present several time to set all variables
  private static final String A_VARIABLE = "A text";

  @Resource
  private LanguageToLocaleConverter languageToLocaleConverter; // pb line

  public String myFunction() {
    // logic
  }
}

The code smell is raised on the line already decorated with @Resource. Asking me to annotate it with a decorators, among which there is @Resource. Here is the full text : Annotate this member with "@Autowired", "@Resource", "@Inject", or "@Value", or remove it.

Is there a workaround for this issue, I saw the error reported fiew years ago but not clear answer on this.

Thanks

Hello @TristanL , thanks for reporting this issue.

Could you please share that class code including the imports ? I’m checking the internal code of the rule and I need the imports to fully check.

I’ve tried to reproduce your case, and for me there is no issue reported in that point.

Thanks

Hello @jonathan.vila,

Here a the imports I can share, I only removed my company-specific ones.

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;

import lombok.Setter;
import org.springframework.stereotype.Component;

I did not managed to reproduce it but looking at the global report on our project this is a really common issue on a lot of scanned files.

You have the same imports as me.

Can you check in your SonarQube IDE configuration if you have the issue enabled?

Could you guess which is the difference from your global report in your project and your own configuration ? It’s weird that you and me can not reproduce it but your company SQ is detecting it.

I don’t find this check rule in my sonar IDE list, I’m in version 4.28.0 on VSCode

Hello

I can find it in my VSCode ( 4.29.0) and it is disabled by default, but you need to scroll down

Or you can click on the three dots and search for “java:S3749”

Just by simply removing the @Resource annotation I see the issue, but when I add it then it disappears

Ok, I reproduced the same in IDE. So this seems specific to sonarCloud

Is there any way you could share a screenshot with the issue in SonarQube Cloud ?

No sorry, this is a too sensible part of the code

That’s weird.
For SonarQube Cloud this rule is not activated by default, and you need to fork the “Sonar Way” quality profile and activate it.

But once the rule is activated, the issue is triggered only if the @Resource annotation is not included.

Not raising the issue :

I did not managed to reproduce it since…
I don’t know from where it can come. I’ll let you know if it appends again but in the interval I don’t see what we can do on this one.

1 Like