Use isAssignableFrom instead of relying on ClassCastException#18350
Use isAssignableFrom instead of relying on ClassCastException#18350jdconrad merged 2 commits intoelastic:masterfrom
Conversation
|
I found more of those, updating PR in a minute... |
|
I added more changes around the static casting. It would be good if somebody cross-checks, because some of checks were really crazy (AnalyzerCaster was completely strange to me - I think the fix is right and much simpler)! |
f8572d5 to
a5b0e43
Compare
a5b0e43 to
8195ef9
Compare
|
I agree catching the cast makes the logic hard to understand. personally i find asSubclass much easier to reason about than isAssignableFrom (i think the verb from in the method throws me for a loop every time), but given that we want to return our own exceptions anyway and that there is some "or" logic in here, I think this is better here. Thanks for cleaning it up! cc: @jdconrad |
I know those arguments - especially the "From" confuses. If you once understood how this method should be used, it is quite easy to understand: If you have So don't think about super- or subclass, just think in terms of this assignment possible or not! :-) The problem is similar to some people to understand like For the code in painless, the huge trycatches confuse more than the mental loop :-) P.S.: If you look at |
Thats the real reason why I did it! |
|
Thanks @uschindler! LGTM. If I'm being completely honest, asSubclass was the one I found in examples, so I used that, but this is much cleaner. |
Title says it all :-)