Exchanged instanceof with simple null check

Fixed PR #1827