java:S2226: Please include jakarta.inject to the list of allowed variants

Platform: SonarQube
Language: Java 17
Rule: S2226

Produces a false positive when using java17 and the jakarta-imports for injecting fields (jakarta.inject.Inject). Relevant sourcecode position to change might be

Rule in Github

Probably just have to add the jakarta-inject-package to this list as well.

Example code:

import org.apache.struts.action.Action;
import jakarta.inject.Inject; // has been javax.inject.Inject before migration to 17
public class StartAction extends Action {
  @Inject private Service injectedService;
}

Hey there.

What version of SonarQube are you using?

Hey Colin,

thats SonarQube Version 9.9.1 (build 69595)

Hi Michael, welcome to our community!

This is a known issue for us, as we did not have the time yet to update all of the rules that were dealing with packages migrated from javax to jakarta.

The rule you mentioned is part of a list of rules that need to be updated in this way, you can follow this ticket to check the progress on it. (I have added this thread as a reference for S2226)

Thank you for the report, and have a nice day!

Hey Leonardo,

thanks for the update and the reference to the mentioned ticket.I will have a regular look on that one :slight_smile:

Bye