S2259 Null pointers should not be dereferenced: false positive

Version: SonarQube DE 8.9.9 (build 56886) (LTS)

Following code gives 2 false positives for S2259 on responseEntity.getBody().length() with “getBody() can return null”:

    public String testAnd(ResponseEntity<String> responseEntity) {
        if (responseEntity != null && responseEntity.getBody() != null && responseEntity.getBody().length() > 0) {
            return  responseEntity.getBody();
        }

        if (responseEntity == null || responseEntity.getBody() == null || responseEntity.getBody().length() > 0) {
            return null;
        }
        return  responseEntity.getBody();
    }

This issue doesn’t occur in SonarQube CE 7.9.1 (build 27448)

Hello @sbv

I invite you to have a look at this post, answering a similar issue:

I hope it clarifies the situation.
Best,
Quentin

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.