Program: 70979
Project: 70979
Buggy source:
/** 
 * @param aax
 * @param dAxisStart
 * @param dAxisEnd
 * @param dBlockStart
 * @param dBlockLength
 * @throws ChartException
 * @throws IllegalArgumentException
 */
private final void updateOverlayScales(AllAxes aax,double dAxisStart,double dAxisEnd,double dBlockStart,double dBlockLength) throws ChartException, IllegalArgumentException {
  final Axis[] axa=((ChartWithAxesImpl)cwa).getPrimaryBaseAxes();
  final Axis axPrimaryBase=axa[0];
  final Axis[] axaOrthogonal=((ChartWithAxesImpl)cwa).getOrthogonalAxes(axPrimaryBase,false);
  IntersectionValue iv;
  AutoScale sc=null;
  OneAxis oaxOverlay=null;
  int iTickStyle, iAxisType, j, iTitleLocation;
  int iOverlayCount=aax.getOverlayCount();
  int iOrientation=aax.getOrientation();
  double dStart, dEnd, dAxisLabelsThickness;
  Label laAxisTitle;
  Scale scModel;
  Series[] sea=cwa.getSeries(IConstants.ORTHOGONAL);
  Map<?,?> seriesRenderingHints=rtc.getSeriesRenderers();
  for (int i=0; i < iOverlayCount; i++) {
    j=iOverlayCount - i - 1;
    oaxOverlay=aax.getOverlay(j);
    iTickStyle=oaxOverlay.getCombinedTickStyle();
    iTitleLocation=oaxOverlay.getTitlePosition();
    laAxisTitle=oaxOverlay.getTitle();
    iAxisType=getAxisType(axaOrthogonal[j]);
    scModel=axaOrthogonal[j].getScale();
    sc=AutoScale.computeScale(ids,oaxOverlay,new DataSetIterator(getMinMax(axaOrthogonal[j],iAxisType),iAxisType),iAxisType,dAxisStart,dAxisEnd,scModel,axaOrthogonal[j].getFormatSpecifier(),rtc,AUTO,1,iMarginPercent);
    oaxOverlay.set(sc);
    iv=oaxOverlay.getIntersectionValue();
    dStart=sc.getStart();
    dEnd=sc.getEnd();
    sc.computeTicks(ids,oaxOverlay.getLabel(),oaxOverlay.getLabelPosition(),iOrientation,dStart,dEnd,true,null);
    if (!sc.isStepFixed()) {
      final Object[] oaMinMax=sc.getMinMax();
      while (!sc.checkFit(ids,oaxOverlay.getLabel(),oaxOverlay.getLabelPosition())) {
        if (!sc.zoomOut()) {
          break;
        }
        sc.updateAxisMinMax(oaMinMax[0],oaMinMax[1]);
        sc.computeTicks(ids,oaxOverlay.getLabel(),oaxOverlay.getLabelPosition(),iOrientation,dStart,dEnd,true,null);
      }
    }
    dAxisLabelsThickness=sc.computeAxisLabelThickness(ids,oaxOverlay.getLabel(),iOrientation);
    double[] dDecorationThickness={0,0};
    for (int t=0; t < sea.length; t++) {
      LegendItemRenderingHints lirh=(LegendItemRenderingHints)seriesRenderingHints.get(sea[t]);
      if (lirh != null && lirh.getRenderer() instanceof AxesRenderer) {
        IAxesDecorator iad=((AxesRenderer)lirh.getRenderer()).getAxesDecorator(oaxOverlay);
        if (iad != null) {
          double[] thickness=iad.computeDecorationThickness(ids,oaxOverlay);
          if (thickness[0] > dDecorationThickness[0]) {
            dDecorationThickness[0]=thickness[0];
          }
          if (thickness[1] > dDecorationThickness[1]) {
            dDecorationThickness[1]=thickness[1];
          }
        }
      }
    }
    double dAxisTitleThickness=0;
    sc.resetShifts();
    if (iOrientation == VERTICAL) {
      double dX=0, dX1=0, dX2=0;
      final boolean bTicksLeft=(iTickStyle & TICK_LEFT) == TICK_LEFT;
      final boolean bTicksRight=(iTickStyle & TICK_RIGHT) == TICK_RIGHT;
      final double dAppliedYAxisPlotSpacing=dYAxisPlotSpacing;
      if (laAxisTitle.isVisible()) {
        final String sPreviousValue=laAxisTitle.getCaption().getValue();
        laAxisTitle.getCaption().setValue(rtc.externalizedMessage(sPreviousValue));
        dAxisTitleThickness=computeBox(ids,iTitleLocation,laAxisTitle,0,0,ChartUtil.computeHeightOfOrthogonalAxisTitle(cwa,getDisplayServer())).getWidth();
        laAxisTitle.getCaption().setValue(sPreviousValue);
      }
      if (iv.getType() == IConstants.MIN) {
        dX=dBlockStart;
        dX-=dAppliedYAxisPlotSpacing;
        dX1=dX;
        dX2=dX;
        if (bTicksLeft) {
          dX1-=getTickSize();
        }
        if (oaxOverlay.getLabelPosition() == LEFT) {
          dX1-=Math.max(dAxisLabelsThickness,dDecorationThickness[0]);
          dX2+=Math.max(bTicksRight ? getTickSize() : 0,dAppliedYAxisPlotSpacing);
        }
 else         if (oaxOverlay.getLabelPosition() == RIGHT) {
          dX1-=dDecorationThickness[0];
          dX2+=Math.max((bTicksRight ? getTickSize() : 0) + dAxisLabelsThickness,dAppliedYAxisPlotSpacing);
        }
        if (iTitleLocation == LEFT) {
          dX1-=dAxisTitleThickness;
        }
 else         if (iTitleLocation == RIGHT) {
          dX2+=dAxisTitleThickness;
        }
        if (dX1 < dBlockStart) {
          final double dDelta=(dBlockStart - dX1);
          dX1=dBlockStart;
          dX+=dDelta;
          dX2+=dDelta;
        }
        dBlockStart+=(dX2 - dX1);
      }
 else       if (iv.getType() == IConstants.MAX) {
        dX=dBlockStart + dBlockLength;
        dX+=dAppliedYAxisPlotSpacing;
        dX1=dX;
        dX2=dX;
        if (bTicksRight) {
          dX2+=getTickSize();
        }
        if (oaxOverlay.getLabelPosition() == RIGHT) {
          dX2+=Math.max(dAxisLabelsThickness,dDecorationThickness[1]);
          dX1-=Math.max(bTicksLeft ? getTickSize() : 0,dAppliedYAxisPlotSpacing);
        }
 else         if (oaxOverlay.getLabelPosition() == LEFT) {
          dX1-=Math.max((bTicksLeft ? getTickSize() : 0) + dAxisLabelsThickness,dAppliedYAxisPlotSpacing);
          dX2+=dDecorationThickness[1];
        }
        if (iTitleLocation == LEFT) {
          dX1-=dAxisTitleThickness;
        }
 else         if (iTitleLocation == RIGHT) {
          dX2+=dAxisTitleThickness;
        }
        if (dX2 > dBlockStart + dBlockLength) {
          final double dDelta=dX2 - (dBlockStart + dBlockLength);
          dX2=dBlockStart + dBlockLength;
          dX-=dDelta;
          dX1-=dDelta;
        }
      }
      dBlockLength-=dX2 - dX1;
      double dDelta=0;
      if (iv.getType() == IConstants.MIN) {
        dDelta=-insCA.getLeft();
      }
 else       if (iv.getType() == IConstants.MAX) {
        dDelta=insCA.getRight();
      }
      oaxOverlay.setAxisCoordinate(dX + dDelta);
      oaxOverlay.setTitleCoordinate((iTitleLocation == LEFT) ? dX1 + dDelta - 1 : dX2 + 1 - dAxisTitleThickness + dDelta);
    }
 else     if (iOrientation == HORIZONTAL) {
      double dY=0, dY1=dY, dY2=dY;
      final boolean bTicksAbove=(iTickStyle & TICK_ABOVE) == TICK_ABOVE;
      final boolean bTicksBelow=(iTickStyle & TICK_BELOW) == TICK_BELOW;
      final double dAppliedXAxisPlotSpacing=dXAxisPlotSpacing;
      if (laAxisTitle.isVisible()) {
        final String sPreviousValue=laAxisTitle.getCaption().getValue();
        laAxisTitle.getCaption().setValue(rtc.externalizedMessage(sPreviousValue));
        dAxisTitleThickness=computeBox(ids,iTitleLocation,laAxisTitle,0,0,ChartUtil.computeHeightOfOrthogonalAxisTitle(cwa,getDisplayServer())).getHeight();
        laAxisTitle.getCaption().setValue(sPreviousValue);
      }
      if (iv.getType() == IConstants.MAX) {
        dY=dBlockStart;
        dY-=dAppliedXAxisPlotSpacing;
        dY1=dY;
        dY2=dY;
        if (bTicksAbove) {
          dY1-=getTickSize();
        }
        if (oaxOverlay.getLabelPosition() == ABOVE) {
          dY1-=Math.max(dAxisLabelsThickness,dDecorationThickness[0]);
          dY2+=Math.max(bTicksBelow ? getTickSize() : 0,dAppliedXAxisPlotSpacing);
        }
 else         if (oaxOverlay.getLabelPosition() == BELOW) {
          dY1-=dDecorationThickness[0];
          dY2+=Math.max((bTicksBelow ? getTickSize() : 0) + dAxisLabelsThickness,dAppliedXAxisPlotSpacing);
        }
        if (iTitleLocation == ABOVE) {
          dY1-=dAxisTitleThickness;
        }
 else         if (iTitleLocation == BELOW) {
          dY2+=dAxisTitleThickness;
        }
        if (dY1 < dBlockStart) {
          final double dDelta=(dBlockStart - dY1);
          dY1=dBlockStart;
          dY+=dDelta;
          dY2+=dDelta;
        }
        dBlockStart+=(dY2 - dY1);
      }
 else       if (iv.getType() == IConstants.MIN) {
        dY=dBlockStart + dBlockLength;
        dY+=dAppliedXAxisPlotSpacing;
        dY1=dY;
        dY2=dY;
        if (bTicksBelow) {
          dY2+=getTickSize();
        }
        if (oaxOverlay.getLabelPosition() == BELOW) {
          dY2+=Math.max(dAxisLabelsThickness,dDecorationThickness[1]);
          dY1-=Math.max(bTicksAbove ? getTickSize() : 0,dAppliedXAxisPlotSpacing);
        }
 else         if (oaxOverlay.getLabelPosition() == ABOVE) {
          dY1-=Math.max((bTicksAbove ? getTickSize() : 0) + dAxisLabelsThickness,dAppliedXAxisPlotSpacing);
          dY2+=dDecorationThickness[1];
        }
        if (iTitleLocation == ABOVE) {
          dY1-=dAxisTitleThickness;
        }
 else         if (iTitleLocation == BELOW) {
          dY2+=dAxisTitleThickness;
        }
        if (dY2 > dBlockStart + dBlockLength) {
          final double dDelta=dY2 - (dBlockStart + dBlockLength);
          dY2=dBlockStart + dBlockLength;
          dY-=dDelta;
          dY1-=dDelta;
        }
      }
      double dDelta=0;
      if (iv.getType() == IConstants.MAX) {
        dDelta=-insCA.getTop();
      }
 else       if (iv.getType() == IConstants.MIN) {
        dDelta=insCA.getBottom();
      }
      oaxOverlay.setAxisCoordinate(dY + dDelta);
      oaxOverlay.setTitleCoordinate((iTitleLocation == ABOVE) ? dY1 + dDelta - 1 : dY2 + 1 - dAxisTitleThickness + dDelta);
      dBlockLength-=(dY2 - dY1);
    }
  }
  aax.setBlockCordinates(dBlockStart,dBlockLength);
}

Fixed version (ground truth):
/** 
 * @param aax
 * @param dAxisStart
 * @param dAxisEnd
 * @param dBlockStart
 * @param dBlockLength
 * @throws ChartException
 * @throws IllegalArgumentException
 */
private final void updateOverlayScales(AllAxes aax,double dAxisStart,double dAxisEnd,double dBlockStart,double dBlockLength) throws ChartException, IllegalArgumentException {
  final Axis[] axa=((ChartWithAxesImpl)cwa).getPrimaryBaseAxes();
  final Axis axPrimaryBase=axa[0];
  final Axis[] axaOrthogonal=((ChartWithAxesImpl)cwa).getOrthogonalAxes(axPrimaryBase,false);
  IntersectionValue iv;
  AutoScale sc=null;
  OneAxis oaxOverlay=null;
  int iTickStyle, iAxisType, j, iTitleLocation;
  int iOverlayCount=aax.getOverlayCount();
  int iOrientation=aax.getOrientation();
  double dStart, dEnd, dAxisLabelsThickness;
  Label laAxisTitle;
  Scale scModel;
  Series[] sea=cwa.getSeries(IConstants.ORTHOGONAL);
  Map<?,?> seriesRenderingHints=rtc.getSeriesRenderers();
  for (int i=0; i < iOverlayCount; i++) {
    j=iOverlayCount - i - 1;
    oaxOverlay=aax.getOverlay(j);
    iTickStyle=oaxOverlay.getCombinedTickStyle();
    iTitleLocation=oaxOverlay.getTitlePosition();
    laAxisTitle=oaxOverlay.getTitle();
    iAxisType=getAxisType(axaOrthogonal[j]);
    scModel=axaOrthogonal[j].getScale();
    sc=AutoScale.computeScale(ids,oaxOverlay,new DataSetIterator(getMinMax(axaOrthogonal[j],iAxisType),iAxisType),iAxisType,dAxisStart,dAxisEnd,scModel,axaOrthogonal[j].getFormatSpecifier(),rtc,AUTO,1,iMarginPercent);
    oaxOverlay.set(sc);
    iv=oaxOverlay.getIntersectionValue();
    dStart=sc.getStart();
    dEnd=sc.getEnd();
    sc.computeTicks(ids,oaxOverlay.getLabel(),oaxOverlay.getLabelPosition(),iOrientation,dStart,dEnd,true,null);
    if (!sc.isStepFixed()) {
      final Object[] oaMinMax=sc.getMinMax();
      while (!sc.checkFit(ids,oaxOverlay.getLabel(),oaxOverlay.getLabelPosition())) {
        if (!sc.zoomOut()) {
          break;
        }
        sc.updateAxisMinMax(oaMinMax[0],oaMinMax[1]);
        sc.computeTicks(ids,oaxOverlay.getLabel(),oaxOverlay.getLabelPosition(),iOrientation,dStart,dEnd,true,null);
      }
    }
    dAxisLabelsThickness=sc.computeAxisLabelThickness(ids,oaxOverlay.getLabel(),iOrientation);
    double[] dDecorationThickness={0,0};
    for (int t=0; t < sea.length; t++) {
      LegendItemRenderingHints lirh=(LegendItemRenderingHints)seriesRenderingHints.get(sea[t]);
      if (lirh != null && lirh.getRenderer() instanceof AxesRenderer) {
        IAxesDecorator iad=((AxesRenderer)lirh.getRenderer()).getAxesDecorator(oaxOverlay);
        if (iad != null) {
          double[] thickness=iad.computeDecorationThickness(ids,oaxOverlay);
          if (thickness[0] > dDecorationThickness[0]) {
            dDecorationThickness[0]=thickness[0];
          }
          if (thickness[1] > dDecorationThickness[1]) {
            dDecorationThickness[1]=thickness[1];
          }
        }
      }
    }
    double dAxisTitleThickness=0;
    sc.resetShifts();
    if (iOrientation == VERTICAL) {
      double dX=0, dX1=0, dX2=0;
      final boolean bTicksLeft=(iTickStyle & TICK_LEFT) == TICK_LEFT;
      final boolean bTicksRight=(iTickStyle & TICK_RIGHT) == TICK_RIGHT;
      final double dAppliedYAxisPlotSpacing=dYAxisPlotSpacing;
      if (laAxisTitle.isVisible()) {
        final String sPreviousValue=laAxisTitle.getCaption().getValue();
        laAxisTitle.getCaption().setValue(rtc.externalizedMessage(sPreviousValue));
        double maxHeight=boPlot.getHeight();
        double maxWidth=boPlot.getWidth() * AXIS_TITLE_PERCENT;
        LabelLimiter lbLimit=new LabelLimiter(maxWidth,maxHeight,0);
        lbLimit.computeWrapping(ids,laAxisTitle);
        lbLimit=lbLimit.limitLabelSize(ids,laAxisTitle,EnumSet.of(LabelLimiter.Option.FIX_HEIGHT));
        dAxisTitleThickness=lbLimit.getMaxWidth();
        putLabelLimiter(oaxOverlay.getModelAxis().getTitle(),lbLimit);
        laAxisTitle.getCaption().setValue(sPreviousValue);
      }
      if (iv.getType() == IConstants.MIN) {
        dX=dBlockStart;
        dX-=dAppliedYAxisPlotSpacing;
        dX1=dX;
        dX2=dX;
        if (bTicksLeft) {
          dX1-=getTickSize();
        }
        if (oaxOverlay.getLabelPosition() == LEFT) {
          dX1-=Math.max(dAxisLabelsThickness,dDecorationThickness[0]);
          dX2+=Math.max(bTicksRight ? getTickSize() : 0,dAppliedYAxisPlotSpacing);
        }
 else         if (oaxOverlay.getLabelPosition() == RIGHT) {
          dX1-=dDecorationThickness[0];
          dX2+=Math.max((bTicksRight ? getTickSize() : 0) + dAxisLabelsThickness,dAppliedYAxisPlotSpacing);
        }
        if (iTitleLocation == LEFT) {
          dX1-=dAxisTitleThickness;
        }
 else         if (iTitleLocation == RIGHT) {
          dX2+=dAxisTitleThickness;
        }
        if (dX1 < dBlockStart) {
          final double dDelta=(dBlockStart - dX1);
          dX1=dBlockStart;
          dX+=dDelta;
          dX2+=dDelta;
        }
        dBlockStart+=(dX2 - dX1);
      }
 else       if (iv.getType() == IConstants.MAX) {
        dX=dBlockStart + dBlockLength;
        dX+=dAppliedYAxisPlotSpacing;
        dX1=dX;
        dX2=dX;
        if (bTicksRight) {
          dX2+=getTickSize();
        }
        if (oaxOverlay.getLabelPosition() == RIGHT) {
          dX2+=Math.max(dAxisLabelsThickness,dDecorationThickness[1]);
          dX1-=Math.max(bTicksLeft ? getTickSize() : 0,dAppliedYAxisPlotSpacing);
        }
 else         if (oaxOverlay.getLabelPosition() == LEFT) {
          dX1-=Math.max((bTicksLeft ? getTickSize() : 0) + dAxisLabelsThickness,dAppliedYAxisPlotSpacing);
          dX2+=dDecorationThickness[1];
        }
        if (iTitleLocation == LEFT) {
          dX1-=dAxisTitleThickness;
        }
 else         if (iTitleLocation == RIGHT) {
          dX2+=dAxisTitleThickness;
        }
        if (dX2 > dBlockStart + dBlockLength) {
          final double dDelta=dX2 - (dBlockStart + dBlockLength);
          dX2=dBlockStart + dBlockLength;
          dX-=dDelta;
          dX1-=dDelta;
        }
      }
      dBlockLength-=dX2 - dX1;
      double dDelta=0;
      if (iv.getType() == IConstants.MIN) {
        dDelta=-insCA.getLeft();
      }
 else       if (iv.getType() == IConstants.MAX) {
        dDelta=insCA.getRight();
      }
      oaxOverlay.setAxisCoordinate(dX + dDelta);
      oaxOverlay.setTitleCoordinate((iTitleLocation == LEFT) ? dX1 + dDelta - 1 : dX2 + 1 - dAxisTitleThickness + dDelta);
    }
 else     if (iOrientation == HORIZONTAL) {
      double dY=0, dY1=dY, dY2=dY;
      final boolean bTicksAbove=(iTickStyle & TICK_ABOVE) == TICK_ABOVE;
      final boolean bTicksBelow=(iTickStyle & TICK_BELOW) == TICK_BELOW;
      final double dAppliedXAxisPlotSpacing=dXAxisPlotSpacing;
      if (laAxisTitle.isVisible()) {
        final String sPreviousValue=laAxisTitle.getCaption().getValue();
        laAxisTitle.getCaption().setValue(rtc.externalizedMessage(sPreviousValue));
        double maxHeight=boPlot.getHeight() * AXIS_TITLE_PERCENT;
        double maxWidth=boPlot.getWidth();
        Label laAxisTitleV=aax.getPrimaryOrthogonal().getTitle();
        if (laAxisTitleV.isVisible()) {
          laAxisTitleV=LabelImpl.copyInstance(laAxisTitleV);
          laAxisTitleV.getCaption().setValue(rtc.externalizedMessage(laAxisTitleV.getCaption().getValue()));
          LabelLimiter lbLimitV=new LabelLimiter(boPlot.getWidth() * AXIS_TITLE_PERCENT,boPlot.getWidth(),0);
          lbLimitV.computeWrapping(ids,laAxisTitleV);
          lbLimitV.limitLabelSize(ids,laAxisTitleV);
          maxWidth-=lbLimitV.getMaxWidth();
        }
        LabelLimiter lbLimit=new LabelLimiter(maxWidth,maxHeight,0);
        lbLimit.computeWrapping(ids,laAxisTitle);
        lbLimit=lbLimit.limitLabelSize(ids,laAxisTitle,EnumSet.of(LabelLimiter.Option.FIX_WIDTH));
        dAxisTitleThickness=lbLimit.getMaxHeight();
        putLabelLimiter(oaxOverlay.getModelAxis().getTitle(),lbLimit);
        laAxisTitle.getCaption().setValue(sPreviousValue);
      }
      if (iv.getType() == IConstants.MAX) {
        dY=dBlockStart;
        dY-=dAppliedXAxisPlotSpacing;
        dY1=dY;
        dY2=dY;
        if (bTicksAbove) {
          dY1-=getTickSize();
        }
        if (oaxOverlay.getLabelPosition() == ABOVE) {
          dY1-=Math.max(dAxisLabelsThickness,dDecorationThickness[0]);
          dY2+=Math.max(bTicksBelow ? getTickSize() : 0,dAppliedXAxisPlotSpacing);
        }
 else         if (oaxOverlay.getLabelPosition() == BELOW) {
          dY1-=dDecorationThickness[0];
          dY2+=Math.max((bTicksBelow ? getTickSize() : 0) + dAxisLabelsThickness,dAppliedXAxisPlotSpacing);
        }
        if (iTitleLocation == ABOVE) {
          dY1-=dAxisTitleThickness;
        }
 else         if (iTitleLocation == BELOW) {
          dY2+=dAxisTitleThickness;
        }
        if (dY1 < dBlockStart) {
          final double dDelta=(dBlockStart - dY1);
          dY1=dBlockStart;
          dY+=dDelta;
          dY2+=dDelta;
        }
        dBlockStart+=(dY2 - dY1);
      }
 else       if (iv.getType() == IConstants.MIN) {
        dY=dBlockStart + dBlockLength;
        dY+=dAppliedXAxisPlotSpacing;
        dY1=dY;
        dY2=dY;
        if (bTicksBelow) {
          dY2+=getTickSize();
        }
        if (oaxOverlay.getLabelPosition() == BELOW) {
          dY2+=Math.max(dAxisLabelsThickness,dDecorationThickness[1]);
          dY1-=Math.max(bTicksAbove ? getTickSize() : 0,dAppliedXAxisPlotSpacing);
        }
 else         if (oaxOverlay.getLabelPosition() == ABOVE) {
          dY1-=Math.max((bTicksAbove ? getTickSize() : 0) + dAxisLabelsThickness,dAppliedXAxisPlotSpacing);
          dY2+=dDecorationThickness[1];
        }
        if (iTitleLocation == ABOVE) {
          dY1-=dAxisTitleThickness;
        }
 else         if (iTitleLocation == BELOW) {
          dY2+=dAxisTitleThickness;
        }
        if (dY2 > dBlockStart + dBlockLength) {
          final double dDelta=dY2 - (dBlockStart + dBlockLength);
          dY2=dBlockStart + dBlockLength;
          dY-=dDelta;
          dY1-=dDelta;
        }
      }
      double dDelta=0;
      if (iv.getType() == IConstants.MAX) {
        dDelta=-insCA.getTop();
      }
 else       if (iv.getType() == IConstants.MIN) {
        dDelta=insCA.getBottom();
      }
      oaxOverlay.setAxisCoordinate(dY + dDelta);
      oaxOverlay.setTitleCoordinate((iTitleLocation == ABOVE) ? dY1 + dDelta - 1 : dY2 + 1 - dAxisTitleThickness + dDelta);
      dBlockLength-=(dY2 - dY1);
    }
  }
  aax.setBlockCordinates(dBlockStart,dBlockLength);
}