hmm now that I think about it... can't you extract the two blocks into a method they are almost identical and the if clause in the lower else block is obsolete since res can't be null anymore?