Extend java:S4288 to cover @RestController

(This isn’t so much a feature request as a suggestion for extending an existing rule; hopefully I’ve selected the correct category.)

In brief: java:S4288 recommends constructor injection in place of autowiring fields in Spring controllers, services and repositories. For example, the following snippet (correctly) triggers the rule,

@Controller
public class DemoController {
    @Autowired // java:S4288 matches here
    private FooRepository fooRepository;
}

Unfortunately, the rule doesn’t match when using (the very common) @RestController:

@RestController
public class DemoController {
    @Autowired // no match
    private FooRepository fooRepository;
}

Suggestion: the second snippet should also be considered non-compliant. The rule description should probably also be updated to mention @RestController.

(Snippets tested with SonarLint for Eclipse, v5.9.0.31414.)

Hey!

Thanks for the feedback and sorry for the (very) long time responding. You are right, this is a FN, and it has not been fixed in the last LTS… and it could have been if we would have reacted earlier!

Ticket created to handle it: SONARJAVA-4537.

Cheers,
Michael

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.