Program: 190428
Project: 190428
Buggy source:
private void paintUpperRulerForInterval(Graphics2D g2d,DateTime dtFrom,DateTime dtTo){
  g2d.setFont(settings.informations.font);
  g2d.setColor(settings.informations.fontColor);
  int leftMargin=settings.informations.leftMargin;
  int textTopPosition=settings.informations.textTopPosition;
  int width=getWidth();
  int height=getHeight();
  Interval interval=new Interval(dtFrom,dtTo);
  Period p=interval.toPeriod(PeriodType.days());
  int n=p.getDays();
  int unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString(dtFrom.plusDays(i).dayOfMonth().getAsText(),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Hours.hoursBetween(dtFrom.plusDays(i),dtFrom.plusDays(i + 1)).getHours());
    }
    return;
  }
  unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString(dtFrom.plusDays(i).dayOfMonth().getAsShortText(),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Hours.hoursBetween(dtFrom.plusDays(i),dtFrom.plusDays(i + 1)).getHours());
    }
    return;
  }
  p=interval.toPeriod(PeriodType.days());
  n=p.getDays();
  unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getDayOfMonth() + i),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Hours.hoursBetween(dtFrom.plusDays(i),dtFrom.plusDays(i + 1)).getHours());
    }
    return;
  }
  p=interval.toPeriod(PeriodType.months());
  n=p.getMonths();
  unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsText(),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Days.daysBetween(dtFrom.plusMonths(i),dtFrom.plusMonths(i + 1)).getDays());
    }
    return;
  }
  unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsShortText(),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Days.daysBetween(dtFrom.plusMonths(i),dtFrom.plusMonths(i + 1)).getDays());
    }
    return;
  }
  unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getMonthOfYear() + i),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Days.daysBetween(dtFrom.plusMonths(i),dtFrom.plusMonths(i + 1)).getDays());
    }
    return;
  }
  p=interval.toPeriod(PeriodType.years());
  n=p.getYears();
  unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getYear() + i),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Months.monthsBetween(dtFrom.plusYears(i),dtFrom.plusYears(i + 1)).getMonths());
    }
    return;
  }
  int group=10;
  n=p.getYears() / group;
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getYear() + i * group),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Months.monthsBetween(dtFrom.plusYears(i * group),dtFrom.plusYears((i + 1) * group)).getMonths());
    }
    return;
  }
  group=20;
  n=p.getYears() / group;
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getYear() + i * group),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Months.monthsBetween(dtFrom.plusYears(i * group),dtFrom.plusYears((i + 1) * group)).getMonths());
    }
    return;
  }
  group=50;
  n=p.getYears() / group;
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getYear() + i * group),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Months.monthsBetween(dtFrom.plusYears(i * group),dtFrom.plusYears((i + 1) * group)).getMonths());
    }
    return;
  }
  group=100;
  n=p.getYears() / group;
  if (n / 100 < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getYear() + i * group),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Months.monthsBetween(dtFrom.plusYears(i * group),dtFrom.plusYears((i + 1) * group)).getMonths());
    }
  }
  return;
}

Fixed version (ground truth):
private void paintUpperRulerForInterval(Graphics2D g2d,DateTime dtFrom,DateTime dtTo){
  g2d.setFont(settings.informations.font);
  g2d.setColor(settings.informations.fontColor);
  int leftMargin=settings.informations.leftMargin;
  int textTopPosition=settings.informations.textTopPosition;
  int width=getWidth();
  int height=getHeight();
  Interval interval=new Interval(dtFrom,dtTo);
  Period p=interval.toPeriod(PeriodType.days());
  int n=p.getDays();
  int unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString(dtFrom.plusDays(i).dayOfMonth().getAsText(LOCALE),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Hours.hoursBetween(dtFrom.plusDays(i),dtFrom.plusDays(i + 1)).getHours());
    }
    return;
  }
  unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString(dtFrom.plusDays(i).dayOfMonth().getAsShortText(LOCALE),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Hours.hoursBetween(dtFrom.plusDays(i),dtFrom.plusDays(i + 1)).getHours());
    }
    return;
  }
  p=interval.toPeriod(PeriodType.days());
  n=p.getDays();
  unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getDayOfMonth() + i),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Hours.hoursBetween(dtFrom.plusDays(i),dtFrom.plusDays(i + 1)).getHours());
    }
    return;
  }
  p=interval.toPeriod(PeriodType.months());
  n=p.getMonths();
  unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsText(LOCALE),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Days.daysBetween(dtFrom.plusMonths(i),dtFrom.plusMonths(i + 1)).getDays());
    }
    return;
  }
  unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsShortText(LOCALE),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Days.daysBetween(dtFrom.plusMonths(i),dtFrom.plusMonths(i + 1)).getDays());
    }
    return;
  }
  unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getMonthOfYear() + i),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Days.daysBetween(dtFrom.plusMonths(i),dtFrom.plusMonths(i + 1)).getDays());
    }
    return;
  }
  p=interval.toPeriod(PeriodType.years());
  n=p.getYears();
  unitSize=(int)(settings.informations.fontMetrics.getStringBounds("String_Node_Str",null)).getWidth();
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getYear() + i),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Months.monthsBetween(dtFrom.plusYears(i),dtFrom.plusYears(i + 1)).getMonths());
    }
    return;
  }
  int group=10;
  n=p.getYears() / group;
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getYear() + i * group),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Months.monthsBetween(dtFrom.plusYears(i * group),dtFrom.plusYears((i + 1) * group)).getMonths());
    }
    return;
  }
  group=20;
  n=p.getYears() / group;
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getYear() + i * group),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Months.monthsBetween(dtFrom.plusYears(i * group),dtFrom.plusYears((i + 1) * group)).getMonths());
    }
    return;
  }
  group=50;
  n=p.getYears() / group;
  if (n < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getYear() + i * group),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Months.monthsBetween(dtFrom.plusYears(i * group),dtFrom.plusYears((i + 1) * group)).getMonths());
    }
    return;
  }
  group=100;
  n=p.getYears() / group;
  if (n / 100 < (width / unitSize)) {
    for (int i=0; i < n; i++) {
      g2d.drawString("String_Node_Str" + (dtFrom.getYear() + i * group),leftMargin + 2 + i * (width / n),textTopPosition);
      g2d.drawLine(leftMargin + i * (width / n),2,leftMargin + i * (width / n),height - settings.informations.textBottomMargin);
      paintSmallGraduations(g2d,leftMargin + i * (width / n),leftMargin + (i + 1) * (width / n),Months.monthsBetween(dtFrom.plusYears(i * group),dtFrom.plusYears((i + 1) * group)).getMonths());
    }
  }
  return;
}