Add bounds checking to DomainIndex. Fixes #3599.