Fixed null deref by adding null check.

If factory methods weren't "auto-initialized", a null dereference
would occur in this codepath.

Change-Id: Ic5298701844be1f252a92871031a2ede93059dfa
Merge topic 'auto-init-null-deref' into master

eb22e916 Fixed null deref by adding null check.