Program: 53498
Project: 53498
Buggy source:
/** 
 * Handle keyboard navigation.
 * @param keyCode the key code that was pressed
 */
private void handleKeyNavigation(int keyCode){
  CellTreeNodeView<?> parent=keyboardSelectedNode.getParentNode();
  int parentChildCount=(parent == null) ? 0 : parent.getChildCount();
  int index=keyboardSelectedNode.getIndex();
  int childCount=keyboardSelectedNode.getChildCount();
  boolean isRtl=LocaleInfo.getCurrentLocale().isRTL();
  keyCode=KeyCodes.maybeSwapArrowKeysForRtl(keyCode,isRtl);
switch (keyCode) {
case KeyCodes.KEY_DOWN:
    if (keyboardSelectedNode.isOpen() && childCount > 0) {
      keyboardSelect(keyboardSelectedNode.getChildNode(0),true);
    }
 else     if (index < parentChildCount - 1) {
      keyboardSelect(parent.getChildNode(index + 1),true);
    }
 else {
      CellTreeNodeView<?> curParent=parent;
      CellTreeNodeView<?> nextSibling=null;
      while (curParent != null && curParent != rootNode) {
        CellTreeNodeView<?> grandparent=curParent.getParentNode();
        if (grandparent == null) {
          break;
        }
        int curParentIndex=grandparent.indexOf(curParent);
        if (curParentIndex < grandparent.getChildCount() - 1) {
          nextSibling=grandparent.getChildNode(curParentIndex + 1);
          break;
        }
        curParent=grandparent;
      }
      if (nextSibling != null) {
        keyboardSelect(nextSibling,true);
      }
    }
  break;
case KeyCodes.KEY_UP:
if (index > 0) {
  CellTreeNodeView<?> prevSibling=parent.getChildNode(index - 1);
  if (prevSibling.isOpen() && prevSibling.getChildCount() > 0) {
    prevSibling=prevSibling.getChildNode(prevSibling.getChildCount() - 1);
  }
  keyboardSelect(prevSibling,true);
}
 else if (parent != null && parent != rootNode) {
  keyboardSelect(parent,true);
}
break;
case KeyCodes.KEY_RIGHT:
keyboardNavigateDeep();
break;
case KeyCodes.KEY_LEFT:
keyboardNavigateShallow();
break;
}
}

Fixed version (ground truth):
/** 
 * Handle keyboard navigation.
 * @param keyCode the key code that was pressed
 */
void handleKeyNavigation(int keyCode){
  CellTreeNodeView<?> parent=keyboardSelectedNode.getParentNode();
  int parentChildCount=(parent == null) ? 0 : parent.getChildCount();
  int index=keyboardSelectedNode.getIndex();
  int childCount=keyboardSelectedNode.getChildCount();
  boolean isRtl=LocaleInfo.getCurrentLocale().isRTL();
  keyCode=KeyCodes.maybeSwapArrowKeysForRtl(keyCode,isRtl);
switch (keyCode) {
case KeyCodes.KEY_DOWN:
    if (keyboardSelectedNode.isOpen() && childCount > 0) {
      keyboardSelect(keyboardSelectedNode.getChildNode(0),true);
    }
 else     if (index < parentChildCount - 1) {
      keyboardSelect(parent.getChildNode(index + 1),true);
    }
 else {
      CellTreeNodeView<?> curParent=parent;
      CellTreeNodeView<?> nextSibling=null;
      while (curParent != null && curParent != rootNode) {
        CellTreeNodeView<?> grandparent=curParent.getParentNode();
        if (grandparent == null) {
          break;
        }
        int curParentIndex=grandparent.indexOf(curParent);
        if (curParentIndex < grandparent.getChildCount() - 1) {
          nextSibling=grandparent.getChildNode(curParentIndex + 1);
          break;
        }
        curParent=grandparent;
      }
      if (nextSibling != null) {
        keyboardSelect(nextSibling,true);
      }
    }
  break;
case KeyCodes.KEY_UP:
if (index > 0) {
  CellTreeNodeView<?> prevSibling=parent.getChildNode(index - 1);
  while (prevSibling.isOpen() && prevSibling.getChildCount() > 0) {
    prevSibling=prevSibling.getChildNode(prevSibling.getChildCount() - 1);
  }
  keyboardSelect(prevSibling,true);
}
 else if (parent != null && parent != rootNode) {
  keyboardSelect(parent,true);
}
break;
case KeyCodes.KEY_RIGHT:
keyboardNavigateDeep();
break;
case KeyCodes.KEY_LEFT:
keyboardNavigateShallow();
break;
}
}