LPS-47446

@robertoDiaz can you check my source formatting didn't break anything?

@adolfopa can you check that we didn't leave any other use case where we could get a NPE? We should also have a test for this case. 

Thanks!