using sonarqube to analyze my code and being told "'actor' is null on at least one execution path" for the following code
if (actor.ProducerAgreementIds != null && actor.ProducerAgreementIds.Count > 0)
{
actor.ProducerAgreementIds
is a List<string>
.
isn't this statement already performing a null check? or should it instead be:
if (actor != null && (actor.ProducerAgreementIds != null && actor.ProducerAgreementIds.Count > 0))
{
alternative would just using conditional access
if (actor?.ProducerAgreementIds != null && actor.ProducerAgreementIds.Count > 0)
be appropriate and not cause downstream issues?
thanks!