Program: 7954
Project: 7954
Buggy source:
@Override public void onScroll(AbsListView view,int firstVisibleItem,int visibleItemCount,int totalItemCount){
  if (scrollListener != null) {
    scrollListener.onScroll(view,firstVisibleItem,visibleItemCount,totalItemCount);
  }
  if (getAdapter() == null || getAdapter().getCount() == 0)   return;
  if (areHeadersSticky) {
    if (getChildCount() != 0) {
      View viewToWatch=getChildAt(0);
      for (int i=1; i < getChildCount(); i++) {
        int firstChildDistance;
        if (clippingToPadding) {
          firstChildDistance=Math.abs((viewToWatch.getTop() - getPaddingTop()));
        }
 else {
          firstChildDistance=Math.abs(viewToWatch.getTop());
        }
        int secondChildDistance;
        if (clippingToPadding) {
          secondChildDistance=Math.abs((getChildAt(i).getTop() - getPaddingTop()) - headerHeight);
        }
 else {
          secondChildDistance=Math.abs(getChildAt(i).getTop() - headerHeight);
        }
        if (!(Boolean)viewToWatch.getTag() || ((Boolean)getChildAt(i).getTag() && secondChildDistance < firstChildDistance)) {
          viewToWatch=getChildAt(i);
        }
      }
      if ((Boolean)viewToWatch.getTag()) {
        if (headerHeight < 0)         headerHeight=viewToWatch.findViewById(R.id.header_view).getHeight();
        if (firstVisibleItem == 0 && 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();
        }
      }
    }
    if (Build.VERSION.SDK_INT < 11) {
      if (!clippingToPadding && getPaddingTop() > 0) {
        if (getChildAt(0).getTop() > 0) {
          if (firstVisibleItem > 0)           firstVisibleItem-=1;
        }
      }
    }
    if (oldHeaderId != ((StickyListHeadersAdapter)getAdapter()).getHeaderId(firstVisibleItem)) {
      headerHasChanged=true;
      header=((StickyListHeadersAdapter)getAdapter()).getHeaderView(firstVisibleItem,header);
      header.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,headerHeight));
    }
    oldHeaderId=((StickyListHeadersAdapter)getAdapter()).getHeaderId(firstVisibleItem);
    for (int i=0; i < getChildCount(); i++) {
      if ((Boolean)getChildAt(i).getTag()) {
        if (getChildAt(i).getTop() < (clippingToPadding ? getPaddingTop() : 0)) {
          getChildAt(i).findViewById(R.id.header_view).setVisibility(View.INVISIBLE);
        }
 else {
          getChildAt(i).findViewById(R.id.header_view).setVisibility(View.VISIBLE);
        }
      }
    }
  }
}

Fixed version (ground truth):
@Override public void onScroll(AbsListView view,int firstVisibleItem,int visibleItemCount,int totalItemCount){
  if (scrollListener != null) {
    scrollListener.onScroll(view,firstVisibleItem,visibleItemCount,totalItemCount);
  }
  if (getAdapter() == null || getAdapter().getCount() == 0)   return;
  if (areHeadersSticky) {
    if (getChildCount() != 0) {
      View viewToWatch=super.getChildAt(0);
      for (int i=1; i < getChildCount(); i++) {
        int firstChildDistance;
        if (clippingToPadding) {
          firstChildDistance=Math.abs((viewToWatch.getTop() - getPaddingTop()));
        }
 else {
          firstChildDistance=Math.abs(viewToWatch.getTop());
        }
        int secondChildDistance;
        if (clippingToPadding) {
          secondChildDistance=Math.abs((super.getChildAt(i).getTop() - getPaddingTop()) - headerHeight);
        }
 else {
          secondChildDistance=Math.abs(super.getChildAt(i).getTop() - headerHeight);
        }
        if (!(Boolean)viewToWatch.getTag() || ((Boolean)super.getChildAt(i).getTag() && secondChildDistance < firstChildDistance)) {
          viewToWatch=super.getChildAt(i);
        }
      }
      if ((Boolean)viewToWatch.getTag()) {
        if (headerHeight < 0)         headerHeight=viewToWatch.findViewById(R.id.header_view).getHeight();
        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();
        }
      }
    }
    if (Build.VERSION.SDK_INT < 11) {
      if (!clippingToPadding && getPaddingTop() > 0) {
        if (super.getChildAt(0).getTop() > 0) {
          if (firstVisibleItem > 0)           firstVisibleItem-=1;
        }
      }
    }
    if (oldHeaderId != ((StickyListHeadersAdapter)getAdapter()).getHeaderId(firstVisibleItem)) {
      headerHasChanged=true;
      header=((StickyListHeadersAdapter)getAdapter()).getHeaderView(firstVisibleItem,header);
      header.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,headerHeight));
    }
    oldHeaderId=((StickyListHeadersAdapter)getAdapter()).getHeaderId(firstVisibleItem);
    for (int i=0; i < getChildCount(); i++) {
      if ((Boolean)super.getChildAt(i).getTag()) {
        if (super.getChildAt(i).getTop() < (clippingToPadding ? getPaddingTop() : 0)) {
          super.getChildAt(i).findViewById(R.id.header_view).setVisibility(View.INVISIBLE);
        }
 else {
          super.getChildAt(i).findViewById(R.id.header_view).setVisibility(View.VISIBLE);
        }
      }
    }
  }
}