Prevent NoSuchElementException in Extract trait.

Fixes #1001967
Merge pull request #714 from huitseeker/issue/1001967

Prevent NoSuchElementException in Extract trait.