check if repository is null before dereferencing it