As I have commented elsewhere, it is more readable to finish all NULL-checking and type-checking code before function logic (even just extracting primitives) like this.