Program: 171195
Project: 171195
Buggy source:
private void drawGrid(){
  ctx.clearRect(0,0,width,height);
  ctx.setLineDashes(dashes);
  double majorLineWidth=25 * 0.007 < MIN_MAJOR_LINE_WIDTH ? MIN_MAJOR_LINE_WIDTH : 25 * 0.007;
  double mediumLineWidth=25 * 0.006 < MIN_MEDIUM_LINE_WIDTH ? MIN_MEDIUM_LINE_WIDTH : 25 * 0.005;
  double minorLineWidth=25 * 0.005 < MIN_MINOR_LINE_WIDTH ? MIN_MINOR_LINE_WIDTH : 25 * 0.003;
  Paint minorHGridColor=null == getMinorHGridLinePaint() ? Helper.getColorWithOpacity(yAxis.getMinorTickMarkColor(),getGridOpacity()) : getMinorHGridLinePaint();
  Paint mediumHGridColor=null == getMediumHGridLinePaint() ? Helper.getColorWithOpacity(yAxis.getMediumTickMarkColor(),getGridOpacity()) : getMediumHGridLinePaint();
  Paint majorHGridColor=null == getMinorHGridLinePaint() ? Helper.getColorWithOpacity(yAxis.getMajorTickMarkColor(),getGridOpacity()) : getMinorHGridLinePaint();
  Paint minorVGridColor=null == getMajorVGridLinePaint() ? Helper.getColorWithOpacity(xAxis.getMinorTickMarkColor(),getGridOpacity()) : getMajorVGridLinePaint();
  Paint mediumVGridColor=null == getMediumVGridLinePaint() ? Helper.getColorWithOpacity(xAxis.getMediumTickMarkColor(),getGridOpacity()) : getMediumVGridLinePaint();
  Paint majorVGridColor=null == getMinorVGridLinePaint() ? Helper.getColorWithOpacity(xAxis.getMajorTickMarkColor(),getGridOpacity()) : getMinorVGridLinePaint();
  boolean isLinearXAxis=AxisType.LINEAR == xAxis.getType();
  double minX=xAxis.getMinValue();
  double maxX=xAxis.getMaxValue();
  boolean fullRangeX=(minX < 0 && maxX > 0);
  double minorTickSpaceX=xAxis.getMinorTickSpace();
  double majorTickSpaceX=xAxis.getMajorTickSpace();
  double rangeX=xAxis.getRange();
  double stepSizeX=Math.abs(width / rangeX);
  double zeroPositionX=xAxis.getZeroPosition();
  boolean isLinearYAxis=AxisType.LINEAR == yAxis.getType();
  double minY=yAxis.getMinValue();
  double maxY=yAxis.getMaxValue();
  boolean fullRangeY=(minY < 0 && maxY > 0);
  double minorTickSpaceY=yAxis.getMinorTickSpace();
  double majorTickSpaceY=yAxis.getMajorTickSpace();
  double rangeY=yAxis.getRange();
  double stepSizeY=Math.abs(height / rangeY);
  double zeroPositionY=yAxis.getZeroPosition();
  BigDecimal minorTickSpaceBD=BigDecimal.valueOf(minorTickSpaceX);
  BigDecimal majorTickSpaceBD=BigDecimal.valueOf(majorTickSpaceX);
  BigDecimal mediumCheck2=BigDecimal.valueOf(2 * minorTickSpaceX);
  BigDecimal mediumCheck5=BigDecimal.valueOf(5 * minorTickSpaceX);
  if (isLinearXAxis) {
    boolean isZero;
    double tmpStepSize=minorTickSpaceX;
    BigDecimal counterBD=BigDecimal.valueOf(minX);
    double counter=minX;
    BigDecimal tmpStepBD=new BigDecimal(tmpStepSize);
    tmpStepBD=tmpStepBD.setScale(3,BigDecimal.ROUND_HALF_UP);
    double tmpStep=tmpStepBD.doubleValue();
    for (double i=0; Double.compare(-rangeX - tmpStep,i) <= 0; i-=tmpStep) {
      double startPointX=width + i * stepSizeX;
      double startPointY=0;
      double endPointX=startPointX;
      double endPointY=height;
      if (Double.compare(counterBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(majorTickSpaceBD).doubleValue(),0.0) == 0) {
        isZero=Double.compare(0.0,maxX - counter + minX) == 0;
        if (getMajorVGridLinesVisible()) {
          ctx.setStroke((fullRangeX && isZero) ? xAxis.getZeroColor() : majorVGridColor);
          ctx.setLineWidth(majorLineWidth);
          ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
        }
 else         if (getMinorVGridLinesVisible()) {
          ctx.setStroke((fullRangeX && isZero) ? xAxis.getZeroColor() : minorVGridColor);
          ctx.setLineWidth(minorLineWidth);
          ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
        }
      }
 else       if (getMediumVGridLinesVisible() && Double.compare(minorTickSpaceBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(mediumCheck2).doubleValue(),0.0) != 0.0 && Double.compare(counterBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(mediumCheck5).doubleValue(),0.0) == 0.0) {
        ctx.setStroke(mediumVGridColor);
        ctx.setLineWidth(mediumLineWidth);
        ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
      }
 else       if (getMinorVGridLinesVisible() && Double.compare(counterBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(minorTickSpaceBD).doubleValue(),0.0) == 0) {
        ctx.setStroke(minorVGridColor);
        ctx.setLineWidth(minorLineWidth);
        ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
      }
      counterBD=counterBD.add(minorTickSpaceBD);
      counter=counterBD.doubleValue();
      if (counter > maxX)       break;
    }
  }
 else {
    double logUpperBound=Math.log10(xAxis.getMaxValue());
    double section=width / logUpperBound;
    boolean majorTickMarksVisible=xAxis.getMajorTickMarksVisible();
    boolean minorTickMarksVisible=xAxis.getMinorTickMarksVisible();
    for (double i=0; i <= logUpperBound; i+=1) {
      for (double j=1; j <= 9; j++) {
        BigDecimal value=new BigDecimal(j * Math.pow(10,i));
        double stepSize=i > 0 ? (Math.log10(value.doubleValue()) % i) : Math.log10(value.doubleValue());
        double startPointX=i * section + (stepSize * section);
        double startPointY=0;
        double endPointX=startPointX;
        double endPointY=height;
        if (Helper.isPowerOf10(value.intValue())) {
          if (majorTickMarksVisible) {
            ctx.setStroke(majorVGridColor);
            ctx.setLineWidth(majorLineWidth);
          }
 else           if (minorTickMarksVisible) {
            ctx.setStroke(minorVGridColor);
            ctx.setLineWidth(minorLineWidth);
          }
          ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
        }
 else {
          if (minorTickMarksVisible) {
            ctx.setStroke(minorVGridColor);
            ctx.setLineWidth(minorLineWidth);
            ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
          }
        }
      }
    }
  }
  minorTickSpaceBD=BigDecimal.valueOf(minorTickSpaceY);
  majorTickSpaceBD=BigDecimal.valueOf(majorTickSpaceY);
  mediumCheck2=BigDecimal.valueOf(2 * minorTickSpaceY);
  mediumCheck5=BigDecimal.valueOf(5 * minorTickSpaceY);
  if (isLinearYAxis) {
    boolean isZero;
    double tmpStepSize=minorTickSpaceY;
    BigDecimal counterBD=BigDecimal.valueOf(minY);
    double counter=minY;
    BigDecimal tmpStepBD=new BigDecimal(tmpStepSize);
    tmpStepBD=tmpStepBD.setScale(3,BigDecimal.ROUND_HALF_UP);
    double tmpStep=tmpStepBD.doubleValue();
    for (double i=0; Double.compare(-rangeY - tmpStep,i) <= 0; i-=tmpStep) {
      double startPointX=0;
      double startPointY=height + i * stepSizeY;
      double endPointX=width;
      double endPointY=startPointY;
      if (Double.compare(counterBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(majorTickSpaceBD).doubleValue(),0.0) == 0) {
        isZero=Double.compare(0.0,counter) == 0;
        if (getMajorHGridLinesVisible()) {
          ctx.setStroke((fullRangeY && isZero) ? yAxis.getZeroColor() : majorHGridColor);
          ctx.setLineWidth(majorLineWidth);
          ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
        }
 else         if (getMinorHGridLinesVisible()) {
          ctx.setStroke((fullRangeY && isZero) ? yAxis.getZeroColor() : minorHGridColor);
          ctx.setLineWidth(minorLineWidth);
          ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
        }
      }
 else       if (getMediumHGridLinesVisible() && Double.compare(minorTickSpaceBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(mediumCheck2).doubleValue(),0.0) != 0.0 && Double.compare(counterBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(mediumCheck5).doubleValue(),0.0) == 0.0) {
        ctx.setStroke(mediumHGridColor);
        ctx.setLineWidth(mediumLineWidth);
        ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
      }
 else       if (getMinorHGridLinesVisible() && Double.compare(counterBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(minorTickSpaceBD).doubleValue(),0.0) == 0) {
        ctx.setStroke(minorHGridColor);
        ctx.setLineWidth(minorLineWidth);
        ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
      }
      counterBD=counterBD.add(minorTickSpaceBD);
      counter=counterBD.doubleValue();
      if (counter > maxY)       break;
    }
  }
 else {
    double logUpperBound=Math.log10(yAxis.getMaxValue());
    double section=height / logUpperBound;
    boolean majorTickMarksVisible=yAxis.getMajorTickMarksVisible();
    boolean minorTickMarksVisible=yAxis.getMinorTickMarksVisible();
    double maxPosition=height;
    for (double i=0; i <= logUpperBound; i+=1) {
      for (double j=1; j <= 9; j++) {
        BigDecimal value=new BigDecimal(j * Math.pow(10,i));
        double stepSize=i > 0 ? (Math.log10(value.doubleValue()) % i) : Math.log10(value.doubleValue());
        double startPointX=0;
        double startPointY=maxPosition - i * section - (stepSize * section);
        double endPointX=width;
        double endPointY=startPointY;
        if (Helper.isPowerOf10(value.intValue())) {
          if (majorTickMarksVisible) {
            ctx.setStroke(majorHGridColor);
            ctx.setLineWidth(majorLineWidth);
          }
 else           if (minorTickMarksVisible) {
            ctx.setStroke(minorHGridColor);
            ctx.setLineWidth(minorLineWidth);
          }
          ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
        }
 else {
          if (minorTickMarksVisible) {
            ctx.setStroke(minorHGridColor);
            ctx.setLineWidth(minorLineWidth);
            ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
private void drawGrid(){
  ctx.clearRect(0,0,width,height);
  ctx.setLineDashes(dashes);
  double majorLineWidth=25 * 0.007 < MIN_MAJOR_LINE_WIDTH ? MIN_MAJOR_LINE_WIDTH : 25 * 0.007;
  double mediumLineWidth=25 * 0.006 < MIN_MEDIUM_LINE_WIDTH ? MIN_MEDIUM_LINE_WIDTH : 25 * 0.005;
  double minorLineWidth=25 * 0.005 < MIN_MINOR_LINE_WIDTH ? MIN_MINOR_LINE_WIDTH : 25 * 0.003;
  Paint minorHGridColor=null == getMinorHGridLinePaint() ? Helper.getColorWithOpacity(yAxis.getMinorTickMarkColor(),getGridOpacity()) : getMinorHGridLinePaint();
  Paint mediumHGridColor=null == getMediumHGridLinePaint() ? Helper.getColorWithOpacity(yAxis.getMediumTickMarkColor(),getGridOpacity()) : getMediumHGridLinePaint();
  Paint majorHGridColor=null == getMinorHGridLinePaint() ? Helper.getColorWithOpacity(yAxis.getMajorTickMarkColor(),getGridOpacity()) : getMinorHGridLinePaint();
  Paint minorVGridColor=null == getMajorVGridLinePaint() ? Helper.getColorWithOpacity(xAxis.getMinorTickMarkColor(),getGridOpacity()) : getMajorVGridLinePaint();
  Paint mediumVGridColor=null == getMediumVGridLinePaint() ? Helper.getColorWithOpacity(xAxis.getMediumTickMarkColor(),getGridOpacity()) : getMediumVGridLinePaint();
  Paint majorVGridColor=null == getMinorVGridLinePaint() ? Helper.getColorWithOpacity(xAxis.getMajorTickMarkColor(),getGridOpacity()) : getMinorVGridLinePaint();
  AxisType xAxisType=xAxis.getType();
  double minX=xAxis.getMinValue();
  double maxX=xAxis.getMaxValue();
  boolean fullRangeX=(minX < 0 && maxX > 0);
  double minorTickSpaceX=xAxis.getMinorTickSpace();
  double majorTickSpaceX=xAxis.getMajorTickSpace();
  double rangeX=xAxis.getRange();
  double stepSizeX=Math.abs(width / rangeX);
  double zeroPositionX=xAxis.getZeroPosition();
  AxisType yAxisType=yAxis.getType();
  double minY=yAxis.getMinValue();
  double maxY=yAxis.getMaxValue();
  boolean fullRangeY=(minY < 0 && maxY > 0);
  double minorTickSpaceY=yAxis.getMinorTickSpace();
  double majorTickSpaceY=yAxis.getMajorTickSpace();
  double rangeY=yAxis.getRange();
  double stepSizeY=Math.abs(height / rangeY);
  double zeroPositionY=yAxis.getZeroPosition();
  BigDecimal minorTickSpaceBD=BigDecimal.valueOf(minorTickSpaceX);
  BigDecimal majorTickSpaceBD=BigDecimal.valueOf(majorTickSpaceX);
  BigDecimal mediumCheck2=BigDecimal.valueOf(2 * minorTickSpaceX);
  BigDecimal mediumCheck5=BigDecimal.valueOf(5 * minorTickSpaceX);
  if (AxisType.LINEAR == xAxisType || AxisType.TEXT == xAxisType) {
    boolean isZero;
    double tmpStepSize=minorTickSpaceX;
    BigDecimal counterBD=BigDecimal.valueOf(minX);
    double counter=minX;
    BigDecimal tmpStepBD=new BigDecimal(tmpStepSize);
    tmpStepBD=tmpStepBD.setScale(3,BigDecimal.ROUND_HALF_UP);
    double tmpStep=tmpStepBD.doubleValue();
    for (double i=0; Double.compare(-rangeX - tmpStep,i) <= 0; i-=tmpStep) {
      double startPointX=width + i * stepSizeX;
      double startPointY=0;
      double endPointX=startPointX;
      double endPointY=height;
      if (Double.compare(counterBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(majorTickSpaceBD).doubleValue(),0.0) == 0) {
        isZero=Double.compare(0.0,maxX - counter + minX) == 0;
        if (getMajorVGridLinesVisible()) {
          ctx.setStroke((fullRangeX && isZero) ? xAxis.getZeroColor() : majorVGridColor);
          ctx.setLineWidth(majorLineWidth);
          ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
        }
 else         if (getMinorVGridLinesVisible()) {
          ctx.setStroke((fullRangeX && isZero) ? xAxis.getZeroColor() : minorVGridColor);
          ctx.setLineWidth(minorLineWidth);
          ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
        }
      }
 else       if (getMediumVGridLinesVisible() && Double.compare(minorTickSpaceBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(mediumCheck2).doubleValue(),0.0) != 0.0 && Double.compare(counterBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(mediumCheck5).doubleValue(),0.0) == 0.0) {
        ctx.setStroke(mediumVGridColor);
        ctx.setLineWidth(mediumLineWidth);
        ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
      }
 else       if (getMinorVGridLinesVisible() && Double.compare(counterBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(minorTickSpaceBD).doubleValue(),0.0) == 0) {
        ctx.setStroke(minorVGridColor);
        ctx.setLineWidth(minorLineWidth);
        ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
      }
      counterBD=counterBD.add(minorTickSpaceBD);
      counter=counterBD.doubleValue();
      if (counter > maxX)       break;
    }
  }
 else   if (AxisType.LOGARITHMIC == xAxisType) {
    double logUpperBound=Math.log10(xAxis.getMaxValue());
    double section=width / logUpperBound;
    boolean majorTickMarksVisible=xAxis.getMajorTickMarksVisible();
    boolean minorTickMarksVisible=xAxis.getMinorTickMarksVisible();
    for (double i=0; i <= logUpperBound; i+=1) {
      for (double j=1; j <= 9; j++) {
        BigDecimal value=new BigDecimal(j * Math.pow(10,i));
        double stepSize=i > 0 ? (Math.log10(value.doubleValue()) % i) : Math.log10(value.doubleValue());
        double startPointX=i * section + (stepSize * section);
        double startPointY=0;
        double endPointX=startPointX;
        double endPointY=height;
        if (Helper.isPowerOf10(value.intValue())) {
          if (majorTickMarksVisible) {
            ctx.setStroke(majorVGridColor);
            ctx.setLineWidth(majorLineWidth);
          }
 else           if (minorTickMarksVisible) {
            ctx.setStroke(minorVGridColor);
            ctx.setLineWidth(minorLineWidth);
          }
          ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
        }
 else {
          if (minorTickMarksVisible) {
            ctx.setStroke(minorVGridColor);
            ctx.setLineWidth(minorLineWidth);
            ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
          }
        }
      }
    }
  }
  minorTickSpaceBD=BigDecimal.valueOf(minorTickSpaceY);
  majorTickSpaceBD=BigDecimal.valueOf(majorTickSpaceY);
  mediumCheck2=BigDecimal.valueOf(2 * minorTickSpaceY);
  mediumCheck5=BigDecimal.valueOf(5 * minorTickSpaceY);
  if (AxisType.LINEAR == yAxisType || AxisType.TEXT == yAxisType) {
    boolean isZero;
    double tmpStepSize=minorTickSpaceY;
    BigDecimal counterBD=BigDecimal.valueOf(minY);
    double counter=minY;
    BigDecimal tmpStepBD=new BigDecimal(tmpStepSize);
    tmpStepBD=tmpStepBD.setScale(3,BigDecimal.ROUND_HALF_UP);
    double tmpStep=tmpStepBD.doubleValue();
    for (double i=0; Double.compare(-rangeY - tmpStep,i) <= 0; i-=tmpStep) {
      double startPointX=0;
      double startPointY=height + i * stepSizeY;
      double endPointX=width;
      double endPointY=startPointY;
      if (Double.compare(counterBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(majorTickSpaceBD).doubleValue(),0.0) == 0) {
        isZero=Double.compare(0.0,counter) == 0;
        if (getMajorHGridLinesVisible()) {
          ctx.setStroke((fullRangeY && isZero) ? yAxis.getZeroColor() : majorHGridColor);
          ctx.setLineWidth(majorLineWidth);
          ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
        }
 else         if (getMinorHGridLinesVisible()) {
          ctx.setStroke((fullRangeY && isZero) ? yAxis.getZeroColor() : minorHGridColor);
          ctx.setLineWidth(minorLineWidth);
          ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
        }
      }
 else       if (getMediumHGridLinesVisible() && Double.compare(minorTickSpaceBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(mediumCheck2).doubleValue(),0.0) != 0.0 && Double.compare(counterBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(mediumCheck5).doubleValue(),0.0) == 0.0) {
        ctx.setStroke(mediumHGridColor);
        ctx.setLineWidth(mediumLineWidth);
        ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
      }
 else       if (getMinorHGridLinesVisible() && Double.compare(counterBD.setScale(12,BigDecimal.ROUND_HALF_UP).remainder(minorTickSpaceBD).doubleValue(),0.0) == 0) {
        ctx.setStroke(minorHGridColor);
        ctx.setLineWidth(minorLineWidth);
        ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
      }
      counterBD=counterBD.add(minorTickSpaceBD);
      counter=counterBD.doubleValue();
      if (counter > maxY)       break;
    }
  }
 else   if (AxisType.LOGARITHMIC == yAxisType) {
    double logUpperBound=Math.log10(yAxis.getMaxValue());
    double section=height / logUpperBound;
    boolean majorTickMarksVisible=yAxis.getMajorTickMarksVisible();
    boolean minorTickMarksVisible=yAxis.getMinorTickMarksVisible();
    double maxPosition=height;
    for (double i=0; i <= logUpperBound; i+=1) {
      for (double j=1; j <= 9; j++) {
        BigDecimal value=new BigDecimal(j * Math.pow(10,i));
        double stepSize=i > 0 ? (Math.log10(value.doubleValue()) % i) : Math.log10(value.doubleValue());
        double startPointX=0;
        double startPointY=maxPosition - i * section - (stepSize * section);
        double endPointX=width;
        double endPointY=startPointY;
        if (Helper.isPowerOf10(value.intValue())) {
          if (majorTickMarksVisible) {
            ctx.setStroke(majorHGridColor);
            ctx.setLineWidth(majorLineWidth);
          }
 else           if (minorTickMarksVisible) {
            ctx.setStroke(minorHGridColor);
            ctx.setLineWidth(minorLineWidth);
          }
          ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
        }
 else {
          if (minorTickMarksVisible) {
            ctx.setStroke(minorHGridColor);
            ctx.setLineWidth(minorLineWidth);
            ctx.strokeLine(startPointX,startPointY,endPointX,endPointY);
          }
        }
      }
    }
  }
}