Also, I had to change my code this way because otherwise checkstyle was complaining:

A method should have only one exit point, and that should be the last statement in the method (OnlyOneReturn)