As far as I can tell, there's nothing unsafe about it. You're explicitly checking the type before performing the cast, however you're not using the usual instanceof operator (because it wouldn't work...