<BUG>if (compareRes < 0) {begin = mid + 1;</BUG><CONTEXT>Cell midCell = getCell(mid);int compareRes = comparator.compare(midCell, needle);if (compareRes == 0) {return mid;  // 0 means equals. We found the key}<extra_id_0>} else {end = mid - 1;}</CONTEXT>
if ((compareRes < 0) ^ descending) {begin = mid + 1;