[英]False-positive Sonar issue
Question: why does sonar give me warning ("Change this issue so that it does not always evaluate to "false."). I've been able to prove that if (info == null)
evaluates to true
when the requestEntity
doesn't contain a payload that's found in the db. So how can I get rid of this false positive? Does it have something to do with the @Nullable
, @Checkfornull
, or @Nonnull
annotations? I know the postForObject method uses the @Nullable
annotation. 问题:声纳为什么会向我发出警告(“更改此问题,以便它不会始终评估为“ false”。)。我已经证明,当requestEntity
不执行时, if (info == null)
评估为true
, t包含在db中找到的有效负载,那么我该如何消除这种误报呢?它与@Nullable
, @Checkfornull
或@Nonnull
注释有关吗?我知道postForObject方法使用@Nullable
注释。
Info info = restTemplate.postForObject(connectionString, requestEntity,
Info.class);
if (info == null) {
throw new ApplicationException(Constants.NO_RESULT_ERROR_CODE);
}
Here is the postForObject
method: 这是postForObject
方法:
@Override
@Nullable
public <T> T postForObject(URI url, @Nullable Object request, Class<T> responseType)
throws RestClientException {
RequestCallback requestCallback = httpEntityCallback(request, responseType);
HttpMessageConverterExtractor<T> responseExtractor =
new HttpMessageConverterExtractor<>(responseType, getMessageConverters());
return execute(url, HttpMethod.POST, requestCallback, responseExtractor);
}
You can use // NOSONAR
on the reported line (and probably explain why you ignored this issue). 您可以在报告的行上使用// NOSONAR
(并可能解释为什么您忽略了此问题)。
That's not the best solution but it works (at least, when used in Eclipse). 那不是最好的解决方案,但是它可以工作(至少在Eclipse中使用时)。
You can also use @SuppressWarnings
with the issue type (eg: like squid:02020
). 您也可以将@SuppressWarnings
用于问题类型(例如: squid:02020
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.