This loop looks weird to me. The first `if (entry == null || ...)` block and the second `if (...) { if (...) {` block are pretty much same except that the second one decreases the counter, which means the second block will never be evaluated.