check array length instead of fragile assertion