codegen: Check parameter before calling its interface method
If parameter is NULL, we still access its member, which leads into a core dump. This commit checks it before accessing. However, passing NULL to get interface is still a programmer mistake.
Helps: #2817 (closed)