Fix NPE due to treating files as directories.