Convert using ClassCastException to checking instanceof.
Performance tests show this approach to be faster. Patch by Douglas R. Miles. I modified the patch to remove tabs, so indentation may be slightly off in places. That's something that we need to handle separately, abcl doesn't have a clear indentation policy.