问题:为什么声纳会向我发出警告(“更改此问题,使其不会始终评估为“ false”。)。我已经证明if (info == null)
的评估为true
当requestEntity
不包含在数据库中找到的有效负载时,那么我该如何消除这种误报呢?它与@Nullable
,@Checkfornull
有什么关系,或@Nonnull
注释?我知道postForObject方法使用@Nullable
注释。
Info info = restTemplate.postForObject(connectionString, requestEntity,
Info.class);
if (info == null) {
throw new ApplicationException(Constants.NO_RESULT_ERROR_CODE);
}
这是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);
}
答案 0 :(得分:0)
您可以在报告的行上使用// NOSONAR
(并可能解释为什么您忽略了此问题)。
那不是最好的解决方案,但它可以工作(至少在Eclipse中使用时有效)。