Correct equality check

I'm not entirely sure about the contract here, but the original code is definitely wrong since it will result in a NPE.