Program: 27258
Project: 27258
Buggy source:
private void drawHeaderRowAndEvents(Canvas canvas){
  mHeaderColumnWidth=mTimeTextWidth + mHeaderColumnPadding * 2;
  mWidthPerDay=getWidth() - mHeaderColumnWidth - mColumnGap * (mNumberOfVisibleDays - 1);
  mWidthPerDay=mWidthPerDay / mNumberOfVisibleDays;
  Calendar today=today();
  if (mAreDimensionsInvalid) {
    mEffectiveMinHourHeight=Math.max(mMinHourHeight,(int)((getHeight() - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom) / 24));
    mAreDimensionsInvalid=false;
    if (mScrollToDay != null)     goToDate(mScrollToDay);
    mAreDimensionsInvalid=false;
    if (mScrollToHour >= 0)     goToHour(mScrollToHour);
    mScrollToDay=null;
    mScrollToHour=-1;
    mAreDimensionsInvalid=false;
  }
  if (mIsFirstDraw) {
    mIsFirstDraw=false;
    if (mNumberOfVisibleDays >= 7 && today.get(Calendar.DAY_OF_WEEK) != mFirstDayOfWeek) {
      int difference=7 + (today.get(Calendar.DAY_OF_WEEK) - mFirstDayOfWeek);
      mCurrentOrigin.x+=(mWidthPerDay + mColumnGap) * difference;
    }
  }
  if (mCurrentScrollDirection == Direction.VERTICAL)   mCurrentOrigin.y-=mDistanceY;
  if (mNewHourHeight > 0) {
    if (mNewHourHeight < mEffectiveMinHourHeight)     mNewHourHeight=mEffectiveMinHourHeight;
 else     if (mNewHourHeight > mMaxHourHeight)     mNewHourHeight=mMaxHourHeight;
    mCurrentOrigin.y=(mCurrentOrigin.y / mHourHeight) * mNewHourHeight;
    mHourHeight=mNewHourHeight;
    mNewHourHeight=-1;
  }
  if (mCurrentOrigin.y < getHeight() - mHourHeight * 24 - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom)   mCurrentOrigin.y=getHeight() - mHourHeight * 24 - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom;
  if (mCurrentOrigin.y > 0)   mCurrentOrigin.y=0;
  if (mCurrentScrollDirection == Direction.HORIZONTAL)   mCurrentOrigin.x-=mDistanceX;
  int leftDaysWithGaps=(int)-(Math.ceil(mCurrentOrigin.x / (mWidthPerDay + mColumnGap)));
  float startFromPixel=mCurrentOrigin.x + (mWidthPerDay + mColumnGap) * leftDaysWithGaps + mHeaderColumnWidth;
  float startPixel=startFromPixel;
  Calendar day=(Calendar)today.clone();
  day.add(Calendar.HOUR,6);
  int lineCount=(int)((getHeight() - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom) / mHourHeight) + 1;
  lineCount=(lineCount) * (mNumberOfVisibleDays + 1);
  float[] hourLines=new float[lineCount * 4];
  if (mEventRects != null) {
    for (    EventRect eventRect : mEventRects) {
      eventRect.rectF=null;
    }
  }
  Calendar oldFirstVisibleDay=mFirstVisibleDay;
  mFirstVisibleDay=(Calendar)today.clone();
  mFirstVisibleDay.add(Calendar.DATE,-(Math.round(mCurrentOrigin.x / (mWidthPerDay + mColumnGap))));
  if (!mFirstVisibleDay.equals(oldFirstVisibleDay) && mScrolledListener != null) {
    mScrolledListener.onFirstVisibleDayChanged(mFirstVisibleDay,oldFirstVisibleDay);
  }
  for (int dayNumber=leftDaysWithGaps + 1; dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1; dayNumber++) {
    day=(Calendar)today.clone();
    mLastVisibleDay=(Calendar)day.clone();
    day.add(Calendar.DATE,dayNumber - 1);
    mLastVisibleDay.add(Calendar.DATE,dayNumber - 2);
    boolean sameDay=isSameDay(day,today);
    if (mEventRects == null || mRefreshEvents || (dayNumber == leftDaysWithGaps + 1 && mFetchedPeriod != (int)mWeekViewLoader.toWeekViewPeriodIndex(day) && Math.abs(mFetchedPeriod - mWeekViewLoader.toWeekViewPeriodIndex(day)) > 0.5)) {
      getMoreEvents(day);
      mRefreshEvents=false;
    }
    float start=(startPixel < mHeaderColumnWidth ? mHeaderColumnWidth : startPixel);
    if (mWidthPerDay + startPixel - start > 0) {
      if (mUseNewColoring) {
        boolean isWeekend=(day.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || day.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY);
        Paint pastPaint=isWeekend ? mPastWeekendBackgroundPaint : mPastBackgroundPaint;
        Paint futurePaint=isWeekend ? mFutureWeekendBackgroundPaint : mFutureBackgroundPaint;
        float startY=mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom + mCurrentOrigin.y;
        if (sameDay) {
          Calendar now=Calendar.getInstance();
          float beforeNow=(now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE) / 60.0f) * mHourHeight;
          canvas.drawRect(start,startY,startPixel + mWidthPerDay,startY + beforeNow,pastPaint);
          canvas.drawRect(start,startY + beforeNow,startPixel + mWidthPerDay,getHeight(),futurePaint);
        }
 else         if (day.before(today)) {
          canvas.drawRect(start,startY,startPixel + mWidthPerDay,getHeight(),pastPaint);
        }
 else {
          canvas.drawRect(start,startY,startPixel + mWidthPerDay,getHeight(),futurePaint);
        }
      }
 else {
        canvas.drawRect(start,mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom,startPixel + mWidthPerDay,getHeight(),sameDay ? mTodayBackgroundPaint : mDayBackgroundPaint);
      }
    }
    int i=0;
    for (int hourNumber=0; hourNumber < 24; hourNumber++) {
      float top=mHeaderTextHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * hourNumber + mTimeTextHeight / 2 + mHeaderMarginBottom;
      if (top > mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom - mHourSeparatorHeight && top < getHeight() && startPixel + mWidthPerDay - start > 0) {
        hourLines[i * 4]=start;
        hourLines[i * 4 + 1]=top;
        hourLines[i * 4 + 2]=startPixel + mWidthPerDay;
        hourLines[i * 4 + 3]=top;
        i++;
      }
    }
    canvas.drawLines(hourLines,mHourSeparatorPaint);
    drawEvents(day,startPixel,canvas);
    if (mUseNewColoring && sameDay) {
      float startY=mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom + mCurrentOrigin.y;
      Calendar now=Calendar.getInstance();
      float beforeNow=(now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE) / 60.0f) * mHourHeight;
      canvas.drawLine(start,startY + beforeNow,startPixel + mWidthPerDay,startY + beforeNow,mNowLinePaint);
    }
    startPixel+=mWidthPerDay + mColumnGap;
  }
  canvas.drawRect(0,0,getWidth(),mHeaderTextHeight + mHeaderRowPadding * 2,mHeaderBackgroundPaint);
  startPixel=startFromPixel;
  for (int dayNumber=leftDaysWithGaps + 1; dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1; dayNumber++) {
    day=(Calendar)today.clone();
    day.add(Calendar.DATE,dayNumber - 1);
    boolean sameDay=isSameDay(day,today);
    String dayLabel=getDateTimeInterpreter().interpretDate(day);
    if (dayLabel == null)     throw new IllegalStateException("String_Node_Str");
    canvas.drawText(dayLabel,startPixel + mWidthPerDay / 2,mHeaderTextHeight + mHeaderRowPadding,sameDay ? mTodayHeaderTextPaint : mHeaderTextPaint);
    startPixel+=mWidthPerDay + mColumnGap;
  }
}

Fixed version (ground truth):
private void drawHeaderRowAndEvents(Canvas canvas){
  mHeaderColumnWidth=mTimeTextWidth + mHeaderColumnPadding * 2;
  mWidthPerDay=getWidth() - mHeaderColumnWidth - mColumnGap * (mNumberOfVisibleDays - 1);
  mWidthPerDay=mWidthPerDay / mNumberOfVisibleDays;
  Calendar today=today();
  if (mAreDimensionsInvalid) {
    mEffectiveMinHourHeight=Math.max(mMinHourHeight,(int)((getHeight() - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom) / 24));
    mAreDimensionsInvalid=false;
    if (mScrollToDay != null)     goToDate(mScrollToDay);
    mAreDimensionsInvalid=false;
    if (mScrollToHour >= 0)     goToHour(mScrollToHour);
    mScrollToDay=null;
    mScrollToHour=-1;
    mAreDimensionsInvalid=false;
  }
  if (mIsFirstDraw) {
    mIsFirstDraw=false;
    if (mNumberOfVisibleDays >= 7 && today.get(Calendar.DAY_OF_WEEK) != mFirstDayOfWeek) {
      int difference=7 + (today.get(Calendar.DAY_OF_WEEK) - mFirstDayOfWeek);
      mCurrentOrigin.x+=(mWidthPerDay + mColumnGap) * difference;
    }
  }
  if (mCurrentScrollDirection == Direction.VERTICAL)   mCurrentOrigin.y-=mDistanceY;
  if (mNewHourHeight > 0) {
    if (mNewHourHeight < mEffectiveMinHourHeight)     mNewHourHeight=mEffectiveMinHourHeight;
 else     if (mNewHourHeight > mMaxHourHeight)     mNewHourHeight=mMaxHourHeight;
    mCurrentOrigin.y=(mCurrentOrigin.y / mHourHeight) * mNewHourHeight;
    mHourHeight=mNewHourHeight;
    mNewHourHeight=-1;
  }
  if (mCurrentOrigin.y < getHeight() - mHourHeight * 24 - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom)   mCurrentOrigin.y=getHeight() - mHourHeight * 24 - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom;
  if (mCurrentOrigin.y > 0)   mCurrentOrigin.y=0;
  if (mCurrentScrollDirection == Direction.HORIZONTAL)   mCurrentOrigin.x-=mDistanceX;
  int leftDaysWithGaps=(int)-(Math.ceil(mCurrentOrigin.x / (mWidthPerDay + mColumnGap)));
  float startFromPixel=mCurrentOrigin.x + (mWidthPerDay + mColumnGap) * leftDaysWithGaps + mHeaderColumnWidth;
  float startPixel=startFromPixel;
  Calendar day=(Calendar)today.clone();
  day.add(Calendar.HOUR,6);
  int lineCount=(int)((getHeight() - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom) / mHourHeight) + 1;
  lineCount=(lineCount) * (mNumberOfVisibleDays + 1);
  float[] hourLines=new float[lineCount * 4];
  if (mEventRects != null) {
    for (    EventRect eventRect : mEventRects) {
      eventRect.rectF=null;
    }
  }
  Calendar oldFirstVisibleDay=mFirstVisibleDay;
  mFirstVisibleDay=(Calendar)today.clone();
  mFirstVisibleDay.add(Calendar.DATE,-(Math.round(mCurrentOrigin.x / (mWidthPerDay + mColumnGap))));
  if (!mFirstVisibleDay.equals(oldFirstVisibleDay) && mScrollListener != null) {
    mScrollListener.onFirstVisibleDayChanged(mFirstVisibleDay,oldFirstVisibleDay);
  }
  for (int dayNumber=leftDaysWithGaps + 1; dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1; dayNumber++) {
    day=(Calendar)today.clone();
    mLastVisibleDay=(Calendar)day.clone();
    day.add(Calendar.DATE,dayNumber - 1);
    mLastVisibleDay.add(Calendar.DATE,dayNumber - 2);
    boolean sameDay=isSameDay(day,today);
    if (mEventRects == null || mRefreshEvents || (dayNumber == leftDaysWithGaps + 1 && mFetchedPeriod != (int)mWeekViewLoader.toWeekViewPeriodIndex(day) && Math.abs(mFetchedPeriod - mWeekViewLoader.toWeekViewPeriodIndex(day)) > 0.5)) {
      getMoreEvents(day);
      mRefreshEvents=false;
    }
    float start=(startPixel < mHeaderColumnWidth ? mHeaderColumnWidth : startPixel);
    if (mWidthPerDay + startPixel - start > 0) {
      if (mUseNewColoring) {
        boolean isWeekend=(day.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || day.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY);
        Paint pastPaint=isWeekend ? mPastWeekendBackgroundPaint : mPastBackgroundPaint;
        Paint futurePaint=isWeekend ? mFutureWeekendBackgroundPaint : mFutureBackgroundPaint;
        float startY=mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom + mCurrentOrigin.y;
        if (sameDay) {
          Calendar now=Calendar.getInstance();
          float beforeNow=(now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE) / 60.0f) * mHourHeight;
          canvas.drawRect(start,startY,startPixel + mWidthPerDay,startY + beforeNow,pastPaint);
          canvas.drawRect(start,startY + beforeNow,startPixel + mWidthPerDay,getHeight(),futurePaint);
        }
 else         if (day.before(today)) {
          canvas.drawRect(start,startY,startPixel + mWidthPerDay,getHeight(),pastPaint);
        }
 else {
          canvas.drawRect(start,startY,startPixel + mWidthPerDay,getHeight(),futurePaint);
        }
      }
 else {
        canvas.drawRect(start,mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom,startPixel + mWidthPerDay,getHeight(),sameDay ? mTodayBackgroundPaint : mDayBackgroundPaint);
      }
    }
    int i=0;
    for (int hourNumber=0; hourNumber < 24; hourNumber++) {
      float top=mHeaderTextHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * hourNumber + mTimeTextHeight / 2 + mHeaderMarginBottom;
      if (top > mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom - mHourSeparatorHeight && top < getHeight() && startPixel + mWidthPerDay - start > 0) {
        hourLines[i * 4]=start;
        hourLines[i * 4 + 1]=top;
        hourLines[i * 4 + 2]=startPixel + mWidthPerDay;
        hourLines[i * 4 + 3]=top;
        i++;
      }
    }
    canvas.drawLines(hourLines,mHourSeparatorPaint);
    drawEvents(day,startPixel,canvas);
    if (mUseNewColoring && sameDay) {
      float startY=mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom + mCurrentOrigin.y;
      Calendar now=Calendar.getInstance();
      float beforeNow=(now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE) / 60.0f) * mHourHeight;
      canvas.drawLine(start,startY + beforeNow,startPixel + mWidthPerDay,startY + beforeNow,mNowLinePaint);
    }
    startPixel+=mWidthPerDay + mColumnGap;
  }
  canvas.drawRect(0,0,getWidth(),mHeaderTextHeight + mHeaderRowPadding * 2,mHeaderBackgroundPaint);
  startPixel=startFromPixel;
  for (int dayNumber=leftDaysWithGaps + 1; dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1; dayNumber++) {
    day=(Calendar)today.clone();
    day.add(Calendar.DATE,dayNumber - 1);
    boolean sameDay=isSameDay(day,today);
    String dayLabel=getDateTimeInterpreter().interpretDate(day);
    if (dayLabel == null)     throw new IllegalStateException("String_Node_Str");
    canvas.drawText(dayLabel,startPixel + mWidthPerDay / 2,mHeaderTextHeight + mHeaderRowPadding,sameDay ? mTodayHeaderTextPaint : mHeaderTextPaint);
    startPixel+=mWidthPerDay + mColumnGap;
  }
}