小编典典

SonarQube抱怨将ResponseEntity与通配符一起使用

spring-boot

我使用SpringBoot进行REST Web服务开发,并使用SonarQube进行静态分析。

我的应用程序中有一些端点,它们的外观如下:

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

SonarQube抱怨将ResponseEntity与通配符一起使用,并向我报告了一个 严重问题:“返回参数中不应使用通用通配符类型”

我想知道是否应该在SonarQube中禁用此验证,或者针对这些情况提出不同的返回类型。

你怎么看待这件事?


阅读 387

收藏
2020-05-30

共1个答案

小编典典

最终,我<?>从返回值中删除了代码,现在代码如下所示:

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

SonarQube不再抱怨了,现在的代码似乎更简单了。

2020-05-30