Reputation: 51
In this example below, SonarQube complains that model.toString()
is not null
and (model == null
) is always false
, need some help to understand what can be done to fix it. because the bookmark is initialized as a variable within the if statement and apparently will be null
.
public static class Mapper implements DataStore.ModelMapper<Membership,
MembershipPassDTO> {
@Override
public MembershipPassDTO mapModel(Membership model) {
VALogger.e("SULOD Membership Mapper", "" + model.toString());
if (model == null) {
return new MembershipPassDTO(model, "", "", "", "", "", "");
}
return new MembershipPassDTO(model, model.getVitalityMembershipId(), model.getMembershipNumber(), model.getCustomerNumber(),
model.getVitalityStatus(), model.getMembershipStartDate(), model.getMembershipStatus());
}
}
Upvotes: 5
Views: 1631
Reputation: 3454
whenever you call model.toString()
and your model is null indeed, then your method will throw a NullPoiunterException
.
but if model.toString()
did not throw a NullPointerEcxeption
then it's obvious, that model == null
is always false...
well - that's what SonarQube is trying to tell you...
if you want to get rid of the warning you can do what jensgram suggested:
VALogger.e("SULOD Membership Mapper", ""+model); //implicitly calls toString()
Upvotes: 2