Apparently something slight is changed in the second execution path.
Since all you've presented is a fragment of code floating out there somewhere in the universe, it's hard to know what the first execution path is, much less the second. The code as it stands looks fine. How you're invoking it makes all the difference, and since you haven't provided that there's no way for us to help you identify what's wrong.