Program: 70018
Project: 70018
Buggy source:
/** 
 * Renders the FittingCurve if defined for supported series.
 * @param ipr
 * @param points
 * @param curve
 * @param bDeferred
 * @throws ChartException
 */
protected final void renderFittingCurve(IPrimitiveRenderer ipr,Location[] points,CurveFitting curve,boolean bShowAsTape,boolean bDeferred) throws ChartException {
  if (!curve.getLineAttributes().isSetVisible()) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.RENDERING,"String_Node_Str",Messages.getResourceBundle(getRunTimeContext().getULocale()));
  }
  boolean isTransposed=((ChartWithAxes)getModel()).isTransposed();
  if (curve.getLineAttributes().isVisible()) {
    ScriptHandler.callFunction(getRunTimeContext().getScriptHandler(),ScriptHandler.BEFORE_DRAW_FITTING_CURVE,curve,getRunTimeContext().getScriptContext());
    getRunTimeContext().notifyStructureChange(IStructureDefinitionListener.BEFORE_DRAW_FITTING_CURVE,curve);
    double[] xArray=new double[points.length];
    double[] yArray=new double[points.length];
    for (int i=0; i < xArray.length; i++) {
      xArray[i]=points[i].getX();
      yArray[i]=points[i].getY();
    }
    sort(xArray,yArray,!isTransposed);
    double[] baseArray=xArray, orthogonalArray=yArray;
    if (isTransposed) {
      baseArray=yArray;
      orthogonalArray=xArray;
    }
    FittingCalculator fc=new FittingCalculator(baseArray,orthogonalArray,0.33);
    double[] fitYarray=fc.getFittedValue();
    orthogonalArray=fitYarray;
    if (isTransposed) {
      baseArray=fitYarray;
      orthogonalArray=yArray;
      sort(baseArray,orthogonalArray,false);
    }
    if (curve.getLineAttributes().getColor() != null) {
      CurveRenderer crdr=new CurveRenderer((ChartWithAxes)getModel(),this,curve.getLineAttributes(),goFactory.createLocations(baseArray,orthogonalArray),bShowAsTape,-1,bDeferred,false,null,false,true);
      crdr.draw(ipr);
    }
    if (curve.getLabel().isSetVisible() && curve.getLabel().isVisible()) {
      Label lb=goFactory.copyOf(curve.getLabel());
      final String sPreviousValue=lb.getCaption().getValue();
      lb.getCaption().setValue(getRunTimeContext().externalizedMessage(sPreviousValue));
      BoundingBox bb=cComp.computeBox(getXServer(),IConstants.LEFT,lb,0,0);
      Anchor lbAnchor=curve.getLabelAnchor();
      if (lbAnchor == null) {
        lbAnchor=Anchor.NORTH_LITERAL;
      }
      int horizontal=IConstants.CENTER;
      int vertical=IConstants.ABOVE;
switch (lbAnchor.getValue()) {
case Anchor.WEST:
case Anchor.NORTH_WEST:
case Anchor.SOUTH_WEST:
        horizontal=IConstants.LEFT;
      break;
case Anchor.NORTH:
case Anchor.SOUTH:
    horizontal=IConstants.CENTER;
  break;
case Anchor.EAST:
case Anchor.NORTH_EAST:
case Anchor.SOUTH_EAST:
horizontal=IConstants.RIGHT;
break;
}
switch (lbAnchor.getValue()) {
case Anchor.NORTH:
case Anchor.NORTH_WEST:
case Anchor.NORTH_EAST:
case Anchor.WEST:
case Anchor.EAST:
vertical=IConstants.ABOVE;
break;
case Anchor.SOUTH:
case Anchor.SOUTH_WEST:
case Anchor.SOUTH_EAST:
vertical=IConstants.BELOW;
break;
}
double xs, ys;
if (isTransposed) {
if (horizontal == IConstants.LEFT) {
ys=orthogonalArray[orthogonalArray.length - 1] - bb.getHeight();
horizontal=IConstants.RIGHT;
}
 else if (horizontal == IConstants.RIGHT) {
ys=orthogonalArray[0];
horizontal=IConstants.LEFT;
}
 else {
ys=orthogonalArray[0] + (orthogonalArray[orthogonalArray.length - 1] - orthogonalArray[0]) / 2d - bb.getHeight() / 2d;
}
xs=getFitYPosition(orthogonalArray,baseArray,horizontal,bb.getHeight(),bb.getWidth(),vertical == IConstants.BELOW);
}
 else {
if (horizontal == IConstants.LEFT) {
xs=xArray[0];
}
 else if (horizontal == IConstants.RIGHT) {
xs=xArray[xArray.length - 1] - bb.getWidth();
}
 else {
xs=xArray[0] + (xArray[xArray.length - 1] - xArray[0]) / 2d - bb.getWidth() / 2d;
}
ys=getFitYPosition(xArray,fitYarray,horizontal,bb.getWidth(),bb.getHeight(),vertical == IConstants.ABOVE);
}
bb.setLeft(xs);
bb.setTop(ys);
renderLabel(StructureSource.createSeries(getSeries()),TextRenderEvent.RENDER_TEXT_IN_BLOCK,lb,Position.RIGHT_LITERAL,goFactory.createLocation(bb.getLeft(),bb.getTop()),goFactory.createBounds(bb.getLeft(),bb.getTop(),bb.getWidth(),bb.getHeight()),fDeferredCacheManager.getLastDeferredCache());
}
ScriptHandler.callFunction(getRunTimeContext().getScriptHandler(),ScriptHandler.AFTER_DRAW_FITTING_CURVE,curve,getRunTimeContext().getScriptContext());
getRunTimeContext().notifyStructureChange(IStructureDefinitionListener.AFTER_DRAW_FITTING_CURVE,curve);
}
}

Fixed version (ground truth):
/** 
 * Renders the FittingCurve if defined for supported series.
 * @param ipr
 * @param points
 * @param curve
 * @param bDeferred
 * @throws ChartException
 */
protected final void renderFittingCurve(IPrimitiveRenderer ipr,Location[] points,CurveFitting curve,boolean bShowAsTape,boolean bDeferred) throws ChartException {
  boolean isTransposed=((ChartWithAxes)getModel()).isTransposed();
  if (curve.getLineAttributes().isVisible()) {
    ScriptHandler.callFunction(getRunTimeContext().getScriptHandler(),ScriptHandler.BEFORE_DRAW_FITTING_CURVE,curve,getRunTimeContext().getScriptContext());
    getRunTimeContext().notifyStructureChange(IStructureDefinitionListener.BEFORE_DRAW_FITTING_CURVE,curve);
    double[] xArray=new double[points.length];
    double[] yArray=new double[points.length];
    for (int i=0; i < xArray.length; i++) {
      xArray[i]=points[i].getX();
      yArray[i]=points[i].getY();
    }
    sort(xArray,yArray,!isTransposed);
    double[] baseArray=xArray, orthogonalArray=yArray;
    if (isTransposed) {
      baseArray=yArray;
      orthogonalArray=xArray;
    }
    FittingCalculator fc=new FittingCalculator(baseArray,orthogonalArray,0.33);
    double[] fitYarray=fc.getFittedValue();
    orthogonalArray=fitYarray;
    if (isTransposed) {
      baseArray=fitYarray;
      orthogonalArray=yArray;
      sort(baseArray,orthogonalArray,false);
    }
    if (curve.getLineAttributes().getColor() != null) {
      CurveRenderer crdr=new CurveRenderer((ChartWithAxes)getModel(),this,curve.getLineAttributes(),goFactory.createLocations(baseArray,orthogonalArray),bShowAsTape,-1,bDeferred,false,null,false,true);
      crdr.draw(ipr);
    }
    if (curve.getLabel().isVisible()) {
      Label lb=goFactory.copyOf(curve.getLabel());
      final String sPreviousValue=lb.getCaption().getValue();
      lb.getCaption().setValue(getRunTimeContext().externalizedMessage(sPreviousValue));
      BoundingBox bb=cComp.computeBox(getXServer(),IConstants.LEFT,lb,0,0);
      Anchor lbAnchor=curve.getLabelAnchor();
      if (lbAnchor == null) {
        lbAnchor=Anchor.NORTH_LITERAL;
      }
      int horizontal=IConstants.CENTER;
      int vertical=IConstants.ABOVE;
switch (lbAnchor.getValue()) {
case Anchor.WEST:
case Anchor.NORTH_WEST:
case Anchor.SOUTH_WEST:
        horizontal=IConstants.LEFT;
      break;
case Anchor.NORTH:
case Anchor.SOUTH:
    horizontal=IConstants.CENTER;
  break;
case Anchor.EAST:
case Anchor.NORTH_EAST:
case Anchor.SOUTH_EAST:
horizontal=IConstants.RIGHT;
break;
}
switch (lbAnchor.getValue()) {
case Anchor.NORTH:
case Anchor.NORTH_WEST:
case Anchor.NORTH_EAST:
case Anchor.WEST:
case Anchor.EAST:
vertical=IConstants.ABOVE;
break;
case Anchor.SOUTH:
case Anchor.SOUTH_WEST:
case Anchor.SOUTH_EAST:
vertical=IConstants.BELOW;
break;
}
double xs, ys;
if (isTransposed) {
if (horizontal == IConstants.LEFT) {
ys=orthogonalArray[orthogonalArray.length - 1] - bb.getHeight();
horizontal=IConstants.RIGHT;
}
 else if (horizontal == IConstants.RIGHT) {
ys=orthogonalArray[0];
horizontal=IConstants.LEFT;
}
 else {
ys=orthogonalArray[0] + (orthogonalArray[orthogonalArray.length - 1] - orthogonalArray[0]) / 2d - bb.getHeight() / 2d;
}
xs=getFitYPosition(orthogonalArray,baseArray,horizontal,bb.getHeight(),bb.getWidth(),vertical == IConstants.BELOW);
}
 else {
if (horizontal == IConstants.LEFT) {
xs=xArray[0];
}
 else if (horizontal == IConstants.RIGHT) {
xs=xArray[xArray.length - 1] - bb.getWidth();
}
 else {
xs=xArray[0] + (xArray[xArray.length - 1] - xArray[0]) / 2d - bb.getWidth() / 2d;
}
ys=getFitYPosition(xArray,fitYarray,horizontal,bb.getWidth(),bb.getHeight(),vertical == IConstants.ABOVE);
}
bb.setLeft(xs);
bb.setTop(ys);
renderLabel(StructureSource.createSeries(getSeries()),TextRenderEvent.RENDER_TEXT_IN_BLOCK,lb,Position.RIGHT_LITERAL,goFactory.createLocation(bb.getLeft(),bb.getTop()),goFactory.createBounds(bb.getLeft(),bb.getTop(),bb.getWidth(),bb.getHeight()),fDeferredCacheManager.getLastDeferredCache());
}
ScriptHandler.callFunction(getRunTimeContext().getScriptHandler(),ScriptHandler.AFTER_DRAW_FITTING_CURVE,curve,getRunTimeContext().getScriptContext());
getRunTimeContext().notifyStructureChange(IStructureDefinitionListener.AFTER_DRAW_FITTING_CURVE,curve);
}
}