Fix invalid asInstanceOf cast.