Program: 42939
Project: 42939
Buggy source:
@Nullable protected java.util.List<Integer> findAllVisible(){
  final PsiFile psiFile=PsiDocumentManager.getInstance(project).getPsiFile(document);
  if (psiFile == null) {
    return null;
  }
  CharSequence text=document.getCharsSequence();
  int textLength=document.getTextLength();
  final List<Integer> usages=new ArrayList<Integer>();
  JViewport viewport=editor.getScrollPane().getViewport();
  double linesAbove=viewport.getViewPosition().getY() / editor.getLineHeight();
  ScrollingModelImpl scrollingModel=(ScrollingModelImpl)editor.getScrollingModel();
  Rectangle visibleArea=scrollingModel.getVisibleArea();
  double visibleLines=visibleArea.getHeight() / editor.getLineHeight() + 4;
  int offset=document.getLineStartOffset((int)linesAbove);
  int endLine=(int)(linesAbove + visibleLines);
  int lineCount=document.getLineCount() - 1;
  if (endLine > lineCount) {
    endLine=lineCount;
  }
  int endOffset=document.getLineEndOffset(endLine);
  while (offset < endOffset) {
    FindResult result=findManager.findString(text,offset,findModel,virtualFile);
    if (!result.isStringFound()) {
      break;
    }
    UsageInfo2UsageAdapter usageAdapter=new UsageInfo2UsageAdapter(new UsageInfo(psiFile,result.getStartOffset(),result.getEndOffset()));
    Point point=editor.logicalPositionToXY(editor.offsetToLogicalPosition(usageAdapter.getUsageInfo().getNavigationOffset()));
    if (visibleArea.contains(point)) {
      UsageInfo usageInfo=usageAdapter.getUsageInfo();
      usages.add(usageInfo.getNavigationOffset());
    }
    final int prevOffset=offset;
    offset=result.getEndOffset();
    if (prevOffset == offset) {
      ++offset;
    }
  }
  return usages;
}

Fixed version (ground truth):
@Nullable protected java.util.List<Integer> findAllVisible(){
  final PsiFile psiFile=PsiDocumentManager.getInstance(project).getPsiFile(document);
  if (psiFile == null) {
    return null;
  }
  CharSequence text=document.getCharsSequence();
  final List<Integer> usages=new ArrayList<Integer>();
  JViewport viewport=editor.getScrollPane().getViewport();
  double linesAbove=viewport.getViewPosition().getY() / editor.getLineHeight();
  ScrollingModelImpl scrollingModel=(ScrollingModelImpl)editor.getScrollingModel();
  Rectangle visibleArea=scrollingModel.getVisibleArea();
  double visibleLines=visibleArea.getHeight() / editor.getLineHeight() + 4;
  int offset=document.getLineStartOffset((int)linesAbove);
  int endLine=(int)(linesAbove + visibleLines);
  int lineCount=document.getLineCount() - 1;
  if (endLine > lineCount) {
    endLine=lineCount;
  }
  int endOffset=document.getLineEndOffset(endLine);
  while (offset < endOffset) {
    FindResult result=findManager.findString(text,offset,findModel,virtualFile);
    if (!result.isStringFound()) {
      break;
    }
    UsageInfo2UsageAdapter usageAdapter=new UsageInfo2UsageAdapter(new UsageInfo(psiFile,result.getStartOffset(),result.getEndOffset()));
    Point point=editor.logicalPositionToXY(editor.offsetToLogicalPosition(usageAdapter.getUsageInfo().getNavigationOffset()));
    if (visibleArea.contains(point)) {
      UsageInfo usageInfo=usageAdapter.getUsageInfo();
      usages.add(usageInfo.getNavigationOffset());
    }
    final int prevOffset=offset;
    offset=result.getEndOffset();
    if (prevOffset == offset) {
      ++offset;
    }
  }
  return usages;
}