繁体   English   中英

使用 ResponseEntity 时 Sonarlint 误报 NullPointer 警告 (S2259)

[英]Sonarlint false positive NullPointer warning (S2259) when using ResponseEntity

对于一般的 restTemplate 操作,如:

ResponseEntity<ResponseVO> response = restTemplate.postForEntity(url, entity, ResponseVO.class);
if (response.getBody() != null) {
    String url = response.getBody().getUrl();

重用ResponseEntity时我收到错误的声纳警告:

A "NullPointerException" could be thrown; "getBody()" can return null. sonarlint(java:S2259)

此外,如果我重构并引入变量,则不会出现警告:

ResponseVO body = response.getBody();
if (body != null) {
    String url = body.getUrl();

我不需要添加response != null ,如果添加有不同的(好的)警告:

Remove this expression which always evaluates to "true" [+3 locations]sonarlint(java:S2589)

是 SonarLint 错误吗? 为什么它会警告 NullPointerException?

我怀疑它与 HttpEntity @Nullable定义有关

@Nullable
public T getBody() {

我在jira.sonarsource中没有发现类似的问题

在 Sonar 社区中引发误报并由@DamienUrruty 回答

确实它看起来像一个误报。 也就是说,支持这种情况可能会使规则更加复杂

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM