Revert previous change to allow empty strings in path and rewrite it to still check for null path elements.

This reverts commit 162854fb021f369705b27e3fabc2c8721231ae7f.