Fix a potential ClassCastException.