Revert "Remove some useless defensive checks", fix the misleading test.

This reverts commit 6b0bf0a83d4675174ff1a4a0f7bf275e02e23100.