GenerateAppearances = true; System.NullReferenceException

After years of production, I just changed it from:

if (stamper.AcroFields != null)
{
    f.GenerateAppearances = true;

    foreach(var field in f.Fields)
    {
        f.SetField(field.Key, f.GetField(field.Key));
    }

    stamper.FormFlattening = true;
}

to

if (stamper.AcroFields != null && stamper.AcroFields.GenerateAppearances == true)