声纳假阳性问题

时间:2018-12-27 19:49:36

标签: java sonarqube nullable

问题:为什么声纳会向我发出警告(“更改此问题,使其不会始终评估为“ false”。)。我已经证明if (info == null)的评估为truerequestEntity不包含在数据库中找到的有效负载时,那么我该如何消除这种误报呢?它与@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);
    }

1 个答案:

答案 0 :(得分:0)

您可以在报告的行上使用// NOSONAR(并可能解释为什么您忽略了此问题)。

那不是最好的解决方案,但它可以工作(至少在Eclipse中使用时有效)。