Java separate type checking is not safe