I have a sonar alert on this call minRating.getRatgCaam()
The alert is related to the sonar rule : Null pointers should not be dereferenced.
Ex:
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 validate among other things, if the object minRating is null
public boolean isNR(AgencyRating rating) { return rating == null || isNR(rating.getRatgCaam()); }
When I added the not null validation as sonar suggest. Sonar is ok.
if (minRating !=null && !getRatingUtilities().isNR(minRating)) { return minRating.getRatgCaam(); // no more alert }
Sonar can't determine that the helper method did the null validation. I don't need to do this validation again.
Is my case a false positive ?