Program: 7951
Project: 7951
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=(WrapperView)super.getChildAt(0);
    int firstChildDistance;
    if (clippingToPadding) {
      firstChildDistance=Math.abs((viewToWatch.getTop() - getPaddingTop()));
    }
 else {
      firstChildDistance=Math.abs(viewToWatch.getTop());
    }
    int headerHeight=getHeaderHeight();
    for (int i=1; i < childCount; i++) {
      WrapperView child=(WrapperView)super.getChildAt(i);
      int secondChildDistance;
      if (clippingToPadding) {
        secondChildDistance=Math.abs((child.getTop() - getPaddingTop()) - headerHeight);
      }
 else {
        secondChildDistance=Math.abs(child.getTop() - headerHeight);
      }
      if (!viewToWatch.hasHeader() || (child.hasHeader() && secondChildDistance < firstChildDistance)) {
        viewToWatch=child;
      }
    }
    if (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 || 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);
      }
    }
  }
}