Make sure to read this post before raising a thread here:
Then tell us:
- What language is this for? Java
- Which rule? java:S4488
- Why do you believe it’s a false-positive/false-negative?
- Are you using
- SonarQube Cloud?
- SonarQube Server / Community Build - which version? Sonar Qube Server Data Center Edition v2025.2 (105476)
- SonarQube for IDE - which IDE/version? IntelliJ 2024.3.7 Ultimate Edition
- in connected mode with SonarQube Server / Community Build or SonarQube Cloud? Yes
- How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
@RestController
@RequestMapping(path = "/api/potato", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.ALL_VALUE, method = RequestMethod.GET)
public class MyController{
@GetMapping("/cooked")
public ResponseEntity<Potato> getCookedPotato() {
return new Potato("cooked");
}
}
Function annotations can be switched from @RequestMapping to @GetMapping, but class annotations cannot - @GetMapping can’t be applied to a class. This mapping defines a base path for the whole class, shortening sub-paths in function annotations. We like keeping method=GET on the class as a safe fallback for any @RequestController functions in the class - unless they define a method, they’re limited to GET.