Use default namespace instead of root when namespace() is called with nil

Possible fix for #2049.