Program: 27252
Project: 27252
Buggy source:
/** 
 * Draw the name of the event on top of the event rectangle.
 * @param event The event of which the title (and location) should be drawn.
 * @param rect The rectangle on which the text is to be drawn.
 * @param canvas The canvas to draw upon.
 * @param originalTop The original top position of the rectangle. The rectangle may have some of its portion outside of the visible area.
 * @param originalLeft The original left position of the rectangle. The rectangle may have some of its portion outside of the visible area.
 */
private void drawEventTitle(WeekViewEvent event,RectF rect,Canvas canvas,float originalTop,float originalLeft){
  if (rect.right - rect.left - mEventPadding * 2 < 0)   return;
  SpannableStringBuilder bob=new SpannableStringBuilder();
  if (event.getName() != null) {
    bob.append(event.getName());
    bob.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),0,bob.length(),0);
    bob.append(' ');
  }
  if (event.getLocation() != null) {
    bob.append(event.getLocation());
  }
  StaticLayout textLayout=new StaticLayout(bob,mEventTextPaint,(int)(rect.right - originalLeft - mEventPadding * 2),Layout.Alignment.ALIGN_NORMAL,1.0f,0.0f,false);
  int availableHeight=(int)(rect.bottom - originalTop - mEventPadding * 2);
  int lineHeight=textLayout.getHeight() / textLayout.getLineCount();
  if (lineHeight < availableHeight && textLayout.getHeight() > rect.height() - mEventPadding * 2) {
    int lineCount=textLayout.getLineCount();
    int availableLineCount=(int)Math.floor(lineCount * availableHeight / textLayout.getHeight());
    float widthAvailable=(rect.right - originalLeft - mEventPadding * 2) * availableLineCount;
    textLayout=new StaticLayout(TextUtils.ellipsize(bob,mEventTextPaint,widthAvailable,TextUtils.TruncateAt.END),mEventTextPaint,(int)(rect.right - originalLeft - mEventPadding * 2),Layout.Alignment.ALIGN_NORMAL,1.0f,0.0f,false);
  }
 else   if (lineHeight >= availableHeight) {
    int width=(int)(rect.right - originalLeft - mEventPadding * 2);
    textLayout=new StaticLayout(TextUtils.ellipsize(bob,mEventTextPaint,width,TextUtils.TruncateAt.END),mEventTextPaint,width,Layout.Alignment.ALIGN_NORMAL,1.0f,1.0f,false);
  }
  canvas.save();
  canvas.translate(originalLeft + mEventPadding,originalTop + mEventPadding);
  textLayout.draw(canvas);
  canvas.restore();
}

Fixed version (ground truth):
/** 
 * Draw the name of the event on top of the event rectangle.
 * @param event The event of which the title (and location) should be drawn.
 * @param rect The rectangle on which the text is to be drawn.
 * @param canvas The canvas to draw upon.
 * @param originalTop The original top position of the rectangle. The rectangle may have some of its portion outside of the visible area.
 * @param originalLeft The original left position of the rectangle. The rectangle may have some of its portion outside of the visible area.
 */
private void drawEventTitle(WeekViewEvent event,RectF rect,Canvas canvas,float originalTop,float originalLeft){
  if (rect.right - rect.left - mEventPadding * 2 < 0)   return;
  if (rect.bottom - rect.top - mEventPadding * 2 < 0)   return;
  SpannableStringBuilder bob=new SpannableStringBuilder();
  if (event.getName() != null) {
    bob.append(event.getName());
    bob.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),0,bob.length(),0);
    bob.append(' ');
  }
  if (event.getLocation() != null) {
    bob.append(event.getLocation());
  }
  int availableHeight=(int)(rect.bottom - originalTop - mEventPadding * 2);
  int availableWidth=(int)(rect.right - originalLeft - mEventPadding * 2);
  StaticLayout textLayout=new StaticLayout(bob,mEventTextPaint,availableWidth,Layout.Alignment.ALIGN_NORMAL,1.0f,0.0f,false);
  int lineHeight=textLayout.getHeight() / textLayout.getLineCount();
  if (availableHeight >= lineHeight) {
    int availableLineCount=availableHeight / lineHeight;
    do {
      textLayout=new StaticLayout(TextUtils.ellipsize(bob,mEventTextPaint,availableLineCount * availableWidth,TextUtils.TruncateAt.END),mEventTextPaint,(int)(rect.right - originalLeft - mEventPadding * 2),Layout.Alignment.ALIGN_NORMAL,1.0f,0.0f,false);
      availableLineCount--;
    }
 while (textLayout.getHeight() > availableHeight);
    canvas.save();
    canvas.translate(originalLeft + mEventPadding,originalTop + mEventPadding);
    textLayout.draw(canvas);
    canvas.restore();
  }
}