Search code examples
spring-mvcspring-bootsonarqube

SonarQube complains about using ResponseEntity with a wildcard


I use SpringBoot for REST web services development and SonarQube for static analysis.

I have a few endpoints in my application that look the following way:

@PostMapping
ResponseEntity<?> addSomething(@RequestBody Some object) {
    // some code there
    return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

SonarQube complains about using ResponseEntity with a wildcard, reporting me a Critical issue "Generic wildcard types should not be used in return parameters".

I wonder if I should disable this verification in SonarQube or come up with something different for return type for these cases.

What do you think about it?


Solution

  • Finally I've removed <?> from return value, so the code looks like the following now:

    @PostMapping
    ResponseEntity addSomething(@RequestBody Some object) {
        // some code there
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    

    SonarQube doesn't complain anymore and code seems a little bit simpler now.