Program: 92125
Project: 92125
Buggy source:
/** 
 * Handle key-based navigation in table.
 * @param event
 */
private void handleTableKeyEvent(KeyEvent event){
  int lastEventRank=fTableItemCount - 1;
  int lastPageTopEntryRank=Math.max(0,fTableItemCount - fFullyVisibleRows);
  int previousSelectedEventRank=fSelectedEventRank;
  int selectedRow=fSelectedEventRank - fTableTopEventRank;
  boolean needsRefresh=false;
switch (event.keyCode) {
case SWT.ARROW_DOWN:
{
      event.doit=false;
      if (fSelectedEventRank < lastEventRank) {
        fSelectedEventRank++;
        selectedRow=fSelectedEventRank - fTableTopEventRank;
        if (selectedRow >= fFullyVisibleRows) {
          fTableTopEventRank++;
          needsRefresh=true;
        }
      }
      break;
    }
case SWT.ARROW_UP:
{
    event.doit=false;
    if (fSelectedEventRank > 0) {
      fSelectedEventRank--;
      selectedRow=fSelectedEventRank - fTableTopEventRank;
      if (selectedRow < fFrozenRowCount && fTableTopEventRank > 0) {
        fTableTopEventRank--;
        needsRefresh=true;
      }
    }
    break;
  }
case SWT.END:
{
  event.doit=false;
  fTableTopEventRank=lastPageTopEntryRank;
  fSelectedEventRank=lastEventRank;
  needsRefresh=true;
  break;
}
case SWT.HOME:
{
event.doit=false;
fSelectedEventRank=fFrozenRowCount;
fTableTopEventRank=0;
needsRefresh=true;
break;
}
case SWT.PAGE_DOWN:
{
event.doit=false;
if (fSelectedEventRank < lastEventRank) {
fSelectedEventRank+=fFullyVisibleRows;
if (fSelectedEventRank > lastEventRank) {
  fSelectedEventRank=lastEventRank;
}
selectedRow=fSelectedEventRank - fTableTopEventRank;
if (selectedRow > fFullyVisibleRows - 1) {
  fTableTopEventRank+=fFullyVisibleRows;
  if (fTableTopEventRank > lastPageTopEntryRank) {
    fTableTopEventRank=lastPageTopEntryRank;
  }
  needsRefresh=true;
}
}
break;
}
case SWT.PAGE_UP:
{
event.doit=false;
if (fSelectedEventRank > 0) {
fSelectedEventRank-=fFullyVisibleRows;
if (fSelectedEventRank < fFrozenRowCount) {
fSelectedEventRank=fFrozenRowCount;
}
selectedRow=fSelectedEventRank - fTableTopEventRank;
if (selectedRow < 0) {
fTableTopEventRank-=fFullyVisibleRows;
if (fTableTopEventRank < 0) {
  fTableTopEventRank=0;
}
needsRefresh=true;
}
}
break;
}
default :
{
return;
}
}
boolean done=true;
if (needsRefresh) {
done=refreshTable();
}
 else {
fTable.select(selectedRow);
}
if (fFullyVisibleRows < fTableItemCount) {
fSlider.setSelection(fTableTopEventRank);
}
if (fSelectedEventRank != previousSelectedEventRank && fSelectedEventRank < fTableItemCount) {
if (done) {
Event e=new Event();
e.item=fTable.getSelection()[0];
fTable.notifyListeners(SWT.Selection,e);
}
 else {
fPendingSelection=true;
}
}
}

Fixed version (ground truth):
/** 
 * Handle key-based navigation in table.
 * @param event
 */
private void handleTableKeyEvent(KeyEvent event){
  int lastEventRank=fTableItemCount - 1;
  int lastPageTopEntryRank=Math.max(0,fTableItemCount - fFullyVisibleRows);
  int previousSelectedEventRank=fSelectedEventRank;
  int selectedRow=fSelectedEventRank - fTableTopEventRank;
  boolean needsRefresh=false;
switch (event.keyCode) {
case SWT.ARROW_DOWN:
{
      event.doit=false;
      if (fSelectedEventRank < lastEventRank) {
        fSelectedEventRank++;
        selectedRow=fSelectedEventRank - fTableTopEventRank;
        if (selectedRow == fFullyVisibleRows) {
          fTableTopEventRank++;
          needsRefresh=true;
        }
 else         if (selectedRow < fFrozenRowCount || selectedRow > fFullyVisibleRows) {
          fTableTopEventRank=Math.max(0,Math.min(fSelectedEventRank - fFrozenRowCount,lastPageTopEntryRank));
          needsRefresh=true;
        }
      }
      break;
    }
case SWT.ARROW_UP:
{
    event.doit=false;
    if (fSelectedEventRank > 0) {
      fSelectedEventRank--;
      selectedRow=fSelectedEventRank - fTableTopEventRank;
      if (selectedRow == fFrozenRowCount - 1 && fTableTopEventRank > 0) {
        fTableTopEventRank--;
        needsRefresh=true;
      }
 else       if (selectedRow < fFrozenRowCount || selectedRow > fFullyVisibleRows) {
        fTableTopEventRank=Math.max(0,Math.min(fSelectedEventRank - fFrozenRowCount,lastPageTopEntryRank));
        needsRefresh=true;
      }
    }
    break;
  }
case SWT.END:
{
  event.doit=false;
  fTableTopEventRank=lastPageTopEntryRank;
  fSelectedEventRank=lastEventRank;
  needsRefresh=true;
  break;
}
case SWT.HOME:
{
event.doit=false;
fSelectedEventRank=fFrozenRowCount;
fTableTopEventRank=0;
needsRefresh=true;
break;
}
case SWT.PAGE_DOWN:
{
event.doit=false;
if (fSelectedEventRank < lastEventRank) {
fSelectedEventRank+=fFullyVisibleRows;
if (fSelectedEventRank > lastEventRank) {
  fSelectedEventRank=lastEventRank;
}
selectedRow=fSelectedEventRank - fTableTopEventRank;
if (selectedRow > fFullyVisibleRows + fFrozenRowCount - 1 && selectedRow < 2 * fFullyVisibleRows) {
  fTableTopEventRank+=fFullyVisibleRows;
  if (fTableTopEventRank > lastPageTopEntryRank) {
    fTableTopEventRank=lastPageTopEntryRank;
  }
  needsRefresh=true;
}
 else if (selectedRow < fFrozenRowCount || selectedRow >= 2 * fFullyVisibleRows) {
  fTableTopEventRank=Math.max(0,Math.min(fSelectedEventRank - fFrozenRowCount,lastPageTopEntryRank));
  needsRefresh=true;
}
}
break;
}
case SWT.PAGE_UP:
{
event.doit=false;
if (fSelectedEventRank > 0) {
fSelectedEventRank-=fFullyVisibleRows;
if (fSelectedEventRank < fFrozenRowCount) {
fSelectedEventRank=fFrozenRowCount;
}
selectedRow=fSelectedEventRank - fTableTopEventRank;
if (selectedRow < fFrozenRowCount && selectedRow > -fFullyVisibleRows) {
fTableTopEventRank-=fFullyVisibleRows;
if (fTableTopEventRank < 0) {
  fTableTopEventRank=0;
}
needsRefresh=true;
}
 else if (selectedRow <= -fFullyVisibleRows || selectedRow >= fFullyVisibleRows) {
fTableTopEventRank=Math.max(0,Math.min(fSelectedEventRank - fFrozenRowCount,lastPageTopEntryRank));
needsRefresh=true;
}
}
break;
}
default :
{
return;
}
}
boolean done=true;
if (needsRefresh) {
done=refreshTable();
}
 else {
fTable.select(selectedRow);
}
if (fFullyVisibleRows < fTableItemCount) {
fSlider.setSelection(fTableTopEventRank);
}
if (fSelectedEventRank != previousSelectedEventRank && fSelectedEventRank < fTableItemCount) {
if (done) {
Event e=new Event();
e.item=fTable.getSelection()[0];
fTable.notifyListeners(SWT.Selection,e);
}
 else {
fPendingSelection=true;
}
}
}