Program: 7952
Project: 7952
Buggy source:
private void scrollChanged(int firstVisibleItem){
  if (adapter == null || adapter.getCount() == 0 || !areHeadersSticky)   return;
  firstVisibleItem=getFixedFirstVisibleItem(firstVisibleItem);
  long newHeaderId=adapter.delegate.getHeaderId(firstVisibleItem);
  if (currentHeaderId == null || currentHeaderId != newHeaderId) {
    headerPosition=firstVisibleItem;
    header=adapter.delegate.getHeaderView(headerPosition,header,this);
    measureHeader();
  }
  currentHeaderId=newHeaderId;
  final int childCount=getChildCount();
  if (childCount != 0) {
    WrapperView viewToWatch=null;
    int watchingChildDistance=99999;
    for (int i=0; i < childCount; i++) {
      WrapperView child=(WrapperView)super.getChildAt(i);
      int childDistance;
      if (clippingToPadding) {
        childDistance=child.getTop() - getPaddingTop();
      }
 else {
        childDistance=child.getTop();
      }
      if (childDistance < 0) {
        continue;
      }
      if (viewToWatch == null || !viewToWatch.hasHeader() || (child.hasHeader() && childDistance < watchingChildDistance)) {
        viewToWatch=child;
        watchingChildDistance=childDistance;
      }
    }
    int headerHeight=getHeaderHeight();
    if (viewToWatch != null && viewToWatch.hasHeader()) {
      if (firstVisibleItem == 0 && super.getChildAt(0).getTop() > 0 && !clippingToPadding) {
        headerBottomPosition=0;
      }
 else {
        if (clippingToPadding) {
          headerBottomPosition=Math.min(viewToWatch.getTop(),headerHeight + getPaddingTop());
          headerBottomPosition=headerBottomPosition < getPaddingTop() ? headerHeight + getPaddingTop() : headerBottomPosition;
        }
 else {
          headerBottomPosition=Math.min(viewToWatch.getTop(),headerHeight);
          headerBottomPosition=headerBottomPosition < 0 ? headerHeight : headerBottomPosition;
        }
      }
    }
 else {
      headerBottomPosition=headerHeight;
      if (clippingToPadding) {
        headerBottomPosition+=getPaddingTop();
      }
    }
  }
  int top=clippingToPadding ? getPaddingTop() : 0;
  for (int i=0; i < childCount; i++) {
    WrapperView child=(WrapperView)super.getChildAt(i);
    if (child.hasHeader()) {
      View childHeader=child.header;
      if (child.getTop() < top) {
        childHeader.setVisibility(View.INVISIBLE);
      }
 else {
        childHeader.setVisibility(View.VISIBLE);
      }
    }
  }
}

Fixed version (ground truth):
private void scrollChanged(int firstVisibleItem){
  if (adapter == null) {
    return;
  }
  int adapterCount=adapter.getCount();
  if (adapterCount == 0 || !areHeadersSticky) {
  }
  final int listViewHeaderCount=getHeaderViewsCount();
  firstVisibleItem=getFixedFirstVisibleItem(firstVisibleItem) - listViewHeaderCount;
  if (firstVisibleItem < 0 || firstVisibleItem > adapterCount - 1) {
    header=null;
    currentHeaderId=null;
    headerBottomPosition=-1;
    updateHeaderVisibilities();
    invalidate();
    return;
  }
  long newHeaderId=adapter.delegate.getHeaderId(firstVisibleItem);
  if (currentHeaderId == null || currentHeaderId != newHeaderId) {
    headerPosition=firstVisibleItem;
    header=adapter.delegate.getHeaderView(headerPosition,header,this);
    measureHeader();
  }
  currentHeaderId=newHeaderId;
  int childCount=getChildCount();
  if (childCount != 0) {
    View viewToWatch=null;
    int watchingChildDistance=99999;
    boolean viewToWatchIsFooter=false;
    for (int i=0; i < childCount; i++) {
      View child=super.getChildAt(i);
      boolean childIsFooter=footerViews != null && footerViews.contains(child);
      int childDistance;
      if (clippingToPadding) {
        childDistance=child.getTop() - getPaddingTop();
      }
 else {
        childDistance=child.getTop();
      }
      if (childDistance < 0) {
        continue;
      }
      if (viewToWatch == null || (!viewToWatchIsFooter && !((WrapperView)viewToWatch).hasHeader()) || ((childIsFooter || ((WrapperView)child).hasHeader()) && childDistance < watchingChildDistance)) {
        viewToWatch=child;
        viewToWatchIsFooter=childIsFooter;
        watchingChildDistance=childDistance;
      }
    }
    int headerHeight=getHeaderHeight();
    if (viewToWatch != null && (viewToWatchIsFooter || ((WrapperView)viewToWatch).hasHeader())) {
      if (firstVisibleItem == listViewHeaderCount && super.getChildAt(0).getTop() > 0 && !clippingToPadding) {
        headerBottomPosition=0;
      }
 else {
        if (clippingToPadding) {
          headerBottomPosition=Math.min(viewToWatch.getTop(),headerHeight + getPaddingTop());
          headerBottomPosition=headerBottomPosition < getPaddingTop() ? headerHeight + getPaddingTop() : headerBottomPosition;
        }
 else {
          headerBottomPosition=Math.min(viewToWatch.getTop(),headerHeight);
          headerBottomPosition=headerBottomPosition < 0 ? headerHeight : headerBottomPosition;
        }
      }
    }
 else {
      headerBottomPosition=headerHeight;
      if (clippingToPadding) {
        headerBottomPosition+=getPaddingTop();
      }
    }
  }
  updateHeaderVisibilities();
  invalidate();
}