using sonarqube to analyze my code and being told "'alloc' is null on at least one execution path" for the following code
public RetirementAdvantageProgramSleeveAllocation(VariableDVAPolicy policy, Fund fund)
: base(policy, fund)
{
SleeveAllocation alloc = null;
if (fund.FundAccountType == FundAccountType.PortfolioChoice)
{
alloc = PortfolioChoiceAccountAllocation;
}
else if (fund.FundAccountType == FundAccountType.Heritage)
{
alloc = HeritageAccountAllocation;
}
else if (fund.FundAccountType == FundAccountType.RetirementProtection)
{
alloc = RetirementProtectionAccountAllocation;
}
alloc.PercentValue = fund.Value;
alloc.PercentAllocation = fund.Value;
alloc.Units = 0;
alloc.Value = 0;
}
alloc.PercentValue = fund.Value;
is where i am getting the Possible System.NullReferenceException however is this a false positive? or do i really need to wrap all of these into a if (alloc == null)
thanks