False-positive sonar rule: Null pointers should not be dereferenced

I have a sonar signal for this call minRating.getRatgCaam()

The warning relates to the sonar rule: Null pointers should not be dereferenced.

Example:

AgencyRating minRating = null;
.......
if (!getRatingUtilities().isNR(minRating)) {
    return minRating.getRatgCaam(); //Sonar: Null pointers should not be dereferenced
}

The method isNR(minRating)is a helper method that checks, among other things, if the minRating object is null

public boolean isNR(AgencyRating rating) {
    return rating == null || isNR(rating.getRatgCaam());
}

When I added an unimportant check, as the sonar suggests. Sonar is fine.

if (minRating !=null  && !getRatingUtilities().isNR(minRating)) {
    return minRating.getRatgCaam(); // no more alert
}

Sonar cannot determine that the helper method has performed a null check. I do not need to perform this check again.

Is my case false?

+4
source share
2 answers

, java- sonarqube ( 4.2.1 ) - , , minRating null.

, , .

+3

(sonarqube java analyzer version 4.3.0.7717)

0

Source: https://habr.com/ru/post/1657792/


All Articles