Program: 92328
Project: 92328
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 && fTable.getSelection().length > 0) {
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;
        }
      }
      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;
}
}
}