SonarQube 抱怨使用带有通配符的 ResponseEntity [英] SonarQube complains about using ResponseEntity with a wildcard
问题描述
我使用 SpringBoot 进行 REST Web 服务开发,使用 SonarQube 进行静态分析.
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 抱怨使用带有通配符的 ResponseEntity,向我报告了一个严重问题不应在返回参数中使用通用通配符类型".
SonarQube complains about using ResponseEntity with a wildcard, reporting me a Critical issue "Generic wildcard types should not be used in return parameters".
我想知道我是否应该在 SonarQube 中禁用此验证,或者为这些情况想出不同的返回类型.
I wonder if I should disable this verification in SonarQube or come up with something different for return type for these cases.
你怎么看?
推荐答案
最后我从返回值中删除了 >
,所以代码现在看起来像下面这样:
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 不再抱怨,现在代码似乎更简单了.
SonarQube doesn't complain anymore and code seems a little bit simpler now.
这篇关于SonarQube 抱怨使用带有通配符的 ResponseEntity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!