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.
Info info = restTemplate.postForObject(connectionString, requestEntity,
Info.class);
if (info == null) {
throw new ApplicationException(Constants.NO_RESULT_ERROR_CODE);
}
Here is the postForObject
method:
@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);
}