You can avoid the potential stack overflow problem with a non-recursive solution (though, again, if you don't follow the above suggestions, it'll create an infinite loop)

boolean success = false;...