Program: 69619
Project: 69619
Buggy source:
private final void showRightValue(IPrimitiveRenderer renderer,Location location,Label label,int labelPosition,boolean bShadow){
  IDeviceRenderer idr=(IDeviceRenderer)renderer;
  IChartComputation cComp=idr.getChartComputation();
  Graphics2D g2d=(Graphics2D)idr.getGraphicsContext();
  FontDefinition fontDef=label.getCaption().getFont();
  double dAngleInDegrees=fontDef.getRotation();
  if (bShadow) {
    bShadow=label.getShadowColor() != null;
  }
  Color clrText=(Color)_sxs.getColor(label.getCaption().getColor());
  Color clrBackground=null;
  if (label.getBackground() != null) {
    clrBackground=(Color)_sxs.getColor((ColorDefinition)label.getBackground());
  }
  final ITextMetrics textMetrics=cComp.getTextMetrics(_sxs,label,0);
  AffineTransform afTransform=new AffineTransform(g2d.getTransform());
  location=adjustTextPosition(labelPosition,location,textMetrics,dAngleInDegrees);
  double dX=location.getX(), dY=location.getY();
  dY+=1;
  try {
    final double dFullWidth=textMetrics.getFullWidth();
    final double dHeight=textMetrics.getHeight();
    final double dDescent=textMetrics.getDescent();
    final double dFullHeight=textMetrics.getFullHeight();
    double dXOffset=0, dWidth=0;
    final int lineCount=textMetrics.getLineCount();
    final Insets insets=label.getInsets().scaledInstance(_sxs.getDpiResolution() / 72d);
    final double shadowness=3 * _sxs.getDpiResolution() / 72d;
    final boolean bEmptyText="String_Node_Str".equals(label.getCaption().getValue());
    ChartTextLayout textLayout;
    double dYDiff=dY - dHeight;
    final HorizontalAlignment hAlign=label.getCaption().getFont().getAlignment().getHorizontalAlignment();
    final boolean bRightAligned=hAlign.getValue() == HorizontalAlignment.RIGHT;
    final boolean bCenterAligned=hAlign.getValue() == HorizontalAlignment.CENTER;
    double dAngleInRadians=((-dAngleInDegrees * Math.PI) / 180.0);
    int iRotateX=(int)dX;
    int iRotateY=(int)(dY + dHeight / 2);
    dY+=dHeight / 2;
    if (dAngleInDegrees == 0) {
      double dYHalfOffset=(dFullHeight + dHeight) / 2d;
      if (bShadow) {
        g2d.setPaint(new GradientPaint(new Point2D.Double(dX + shadowness,(dY - dYHalfOffset) + shadowness),(Color)_sxs.getColor(label.getShadowColor()),new Point2D.Double(dX + shadowness + dFullWidth,(dY - dYHalfOffset) + shadowness + dFullHeight),(Color)_sxs.getColor(label.getShadowColor().translucent())));
        fillShadow(g2d,new Rectangle2D.Double(dX + shadowness,(dY - dYHalfOffset) + shadowness,dFullWidth,dFullHeight));
      }
 else {
        final Rectangle2D.Double r2d=new Rectangle2D.Double(dX,dY - dYHalfOffset,dFullWidth,dFullHeight);
        if (clrBackground != null) {
          g2d.setColor(clrBackground);
          g2d.fill(r2d);
        }
        if (!bEmptyText) {
          g2d.setColor(clrText);
          for (int i=0; i < lineCount; i++) {
            textLayout=((ChartTextMetrics)textMetrics).getLayout(i);
            if (bRightAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + dFullWidth - dWidth - insets.getRight();
            }
 else             if (bCenterAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + (dFullWidth - dWidth) / 2;
            }
            textLayout.draw(g2d,(float)(dX + dXOffset + insets.getLeft()),(float)(dY - dYHalfOffset + insets.getTop() + dHeight * (i + 1) - dDescent));
          }
        }
        renderOutline(renderer,label.getOutline(),r2d);
      }
    }
 else     if (dAngleInDegrees > 0 && dAngleInDegrees < 90) {
      double dDeltaX=dHeight * Math.sin(dAngleInRadians);
      double dDeltaY=dHeight * Math.cos(dAngleInRadians) - dHeight / 2;
      dX-=dDeltaX;
      dY+=dDeltaY;
      g2d.rotate(dAngleInRadians,iRotateX - dDeltaX,iRotateY + dDeltaY);
      if (bShadow) {
        g2d.setPaint(new GradientPaint(new Point2D.Double(dX + shadowness,(dYDiff) + shadowness),(Color)_sxs.getColor(label.getShadowColor()),new Point2D.Double(dX + shadowness + dFullWidth,(dYDiff) + shadowness + dFullHeight),(Color)_sxs.getColor(label.getShadowColor().translucent())));
        fillShadow(g2d,new Rectangle2D.Double(dX + shadowness,(dYDiff) + shadowness,dFullWidth,dFullHeight));
      }
 else {
        final Rectangle2D.Double r2d=new Rectangle2D.Double(dX,(dYDiff),dFullWidth,dFullHeight);
        if (clrBackground != null) {
          g2d.setColor(clrBackground);
          g2d.fill(r2d);
        }
        if (!bEmptyText) {
          g2d.setColor(clrText);
          for (int i=0; i < lineCount; i++) {
            textLayout=((ChartTextMetrics)textMetrics).getLayout(i);
            if (bRightAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + dFullWidth - dWidth - insets.getRight();
            }
 else             if (bCenterAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + (dFullWidth - dWidth) / 2;
            }
            textLayout.draw(g2d,(float)(dX + dXOffset + insets.getLeft()),(float)((dY - dDescent + dHeight * i) + insets.getTop()));
          }
        }
        renderOutline(renderer,label.getOutline(),r2d);
      }
    }
 else     if (dAngleInDegrees < 0 && dAngleInDegrees > -90) {
      double dDeltaY=-dHeight / 2;
      dY+=dDeltaY;
      g2d.rotate(dAngleInRadians,iRotateX,iRotateY + dDeltaY);
      if (bShadow) {
        g2d.setPaint(new GradientPaint(new Point2D.Double(dX + shadowness,(dY - dFullHeight) + shadowness),(Color)_sxs.getColor(label.getShadowColor()),new Point2D.Double(dX + shadowness + dFullWidth,(dY - dFullHeight) + shadowness + dFullHeight),(Color)_sxs.getColor(label.getShadowColor().translucent())));
        fillShadow(g2d,new Rectangle2D.Double(dX + shadowness,(dY - dFullHeight) + shadowness,dFullWidth,dFullHeight));
      }
 else {
        final Rectangle2D.Double r2d=new Rectangle2D.Double(dX,dY - dFullHeight,dFullWidth,dFullHeight);
        if (clrBackground != null) {
          g2d.setColor(clrBackground);
          g2d.fill(r2d);
        }
        if (!bEmptyText) {
          g2d.setColor(clrText);
          for (int i=0; i < lineCount; i++) {
            textLayout=((ChartTextMetrics)textMetrics).getLayout(i);
            if (bRightAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + dFullWidth - dWidth - insets.getRight();
            }
 else             if (bCenterAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + (dFullWidth - dWidth) / 2;
            }
            textLayout.draw(g2d,(float)(dX + dXOffset + insets.getLeft()),(float)((dY - dDescent - dHeight * (lineCount - i - 1)) - insets.getBottom()));
          }
        }
        renderOutline(renderer,label.getOutline(),r2d);
      }
    }
 else     if (dAngleInDegrees == 90) {
      double dDeltaX=dHeight;
      double dDeltaY=(dFullWidth - dHeight) / 2;
      dX+=dDeltaX;
      dY+=dDeltaY;
      g2d.rotate(dAngleInRadians,dX,dY);
      if (bShadow) {
        g2d.setPaint(new GradientPaint(new Point2D.Double(dX + shadowness,(dYDiff) + shadowness),(Color)_sxs.getColor(label.getShadowColor()),new Point2D.Double(dX + shadowness + dFullWidth,(dYDiff) + shadowness + dFullHeight),(Color)_sxs.getColor(label.getShadowColor().translucent())));
        fillShadow(g2d,new Rectangle2D.Double(dX + shadowness,(dYDiff) + shadowness,dFullWidth,dFullHeight));
      }
 else {
        final Rectangle2D.Double r2d=new Rectangle2D.Double(dX,dYDiff,dFullWidth,dFullHeight);
        if (clrBackground != null) {
          g2d.setColor(clrBackground);
          g2d.fill(r2d);
        }
        if (!bEmptyText) {
          g2d.setColor(clrText);
          for (int i=0; i < lineCount; i++) {
            textLayout=((ChartTextMetrics)textMetrics).getLayout(i);
            if (bRightAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + dFullWidth - dWidth - insets.getRight();
            }
 else             if (bCenterAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + (dFullWidth - dWidth) / 2;
            }
            textLayout.draw(g2d,(float)(dX + dXOffset + insets.getLeft()),(float)((dY - dDescent + dHeight * i) + insets.getTop()));
          }
        }
        renderOutline(renderer,label.getOutline(),r2d);
      }
    }
 else     if (dAngleInDegrees == -90) {
      double dDeltaX=0;
      double dDeltaY=(dFullWidth + dHeight) / 2;
      dX+=dDeltaX;
      dY-=dDeltaY;
      g2d.rotate(dAngleInRadians,dX,dY);
      if (bShadow) {
        g2d.setPaint(new GradientPaint(new Point2D.Double(dX + shadowness,(dYDiff) + shadowness),(Color)_sxs.getColor(label.getShadowColor()),new Point2D.Double(dX + shadowness + dFullWidth,(dYDiff) + shadowness + dFullHeight),(Color)_sxs.getColor(label.getShadowColor().translucent())));
        fillShadow(g2d,new Rectangle2D.Double(dX + shadowness,(dYDiff) + shadowness,dFullWidth,dFullHeight));
      }
 else {
        final Rectangle2D.Double r2d=new Rectangle2D.Double(dX,dYDiff,dFullWidth,dFullHeight);
        if (clrBackground != null) {
          g2d.setColor(clrBackground);
          g2d.fill(r2d);
        }
        if (!bEmptyText) {
          g2d.setColor(clrText);
          for (int i=0; i < lineCount; i++) {
            textLayout=((ChartTextMetrics)textMetrics).getLayout(i);
            if (bRightAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + dFullWidth - dWidth - insets.getRight();
            }
 else             if (bCenterAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + (dFullWidth - dWidth) / 2;
            }
            textLayout.draw(g2d,(float)(dX + dXOffset + insets.getLeft()),(float)((dY - dDescent + dHeight * i) + insets.getTop()));
          }
        }
        renderOutline(renderer,label.getOutline(),r2d);
      }
    }
  }
  finally {
    g2d.setTransform(afTransform);
    cComp.recycleTextMetrics(textMetrics);
  }
}

Fixed version (ground truth):
private final void showRightValue(IPrimitiveRenderer renderer,Location location,Label label,int labelPosition,boolean bShadow){
  IDeviceRenderer idr=(IDeviceRenderer)renderer;
  IChartComputation cComp=idr.getChartComputation();
  Graphics2D g2d=(Graphics2D)idr.getGraphicsContext();
  FontDefinition fontDef=label.getCaption().getFont();
  double dAngleInDegrees=fontDef.getRotation();
  if (bShadow) {
    bShadow=label.getShadowColor() != null;
  }
  Color clrText=(Color)_sxs.getColor(label.getCaption().getColor());
  Color clrBackground=null;
  if (label.getBackground() != null) {
    clrBackground=(Color)_sxs.getColor((ColorDefinition)label.getBackground());
  }
  final ITextMetrics textMetrics=cComp.getTextMetrics(_sxs,label,0);
  AffineTransform afTransform=new AffineTransform(g2d.getTransform());
  location=adjustTextPosition(labelPosition,location,textMetrics,dAngleInDegrees);
  double dX=location.getX(), dY=location.getY();
  dY+=1;
  try {
    final double dFullWidth=textMetrics.getFullWidth();
    final double dHeight=textMetrics.getHeight();
    final double dDescent=textMetrics.getDescent();
    final double dFullHeight=textMetrics.getFullHeight();
    double dXOffset=0, dWidth=0;
    final int lineCount=textMetrics.getLineCount();
    final Insets insets=label.getInsets().scaledInstance(_sxs.getDpiResolution() / 72d);
    final double shadowness=3 * _sxs.getDpiResolution() / 72d;
    final boolean bEmptyText="String_Node_Str".equals(label.getCaption().getValue());
    ChartTextLayout textLayout;
    double dYDiff;
    final HorizontalAlignment hAlign=label.getCaption().getFont().getAlignment().getHorizontalAlignment();
    final boolean bRightAligned=hAlign.getValue() == HorizontalAlignment.RIGHT;
    final boolean bCenterAligned=hAlign.getValue() == HorizontalAlignment.CENTER;
    double dAngleInRadians=((-dAngleInDegrees * Math.PI) / 180.0);
    int iRotateX=(int)dX;
    int iRotateY=(int)(dY + dHeight / 2);
    dY+=dHeight / 2;
    if (dAngleInDegrees == 0) {
      double dYHalfOffset=(dFullHeight + dHeight) / 2d;
      if (bShadow) {
        g2d.setPaint(new GradientPaint(new Point2D.Double(dX + shadowness,(dY - dYHalfOffset) + shadowness),(Color)_sxs.getColor(label.getShadowColor()),new Point2D.Double(dX + shadowness + dFullWidth,(dY - dYHalfOffset) + shadowness + dFullHeight),(Color)_sxs.getColor(label.getShadowColor().translucent())));
        fillShadow(g2d,new Rectangle2D.Double(dX + shadowness,(dY - dYHalfOffset) + shadowness,dFullWidth,dFullHeight));
      }
 else {
        final Rectangle2D.Double r2d=new Rectangle2D.Double(dX,dY - dYHalfOffset,dFullWidth,dFullHeight);
        if (clrBackground != null) {
          g2d.setColor(clrBackground);
          g2d.fill(r2d);
        }
        if (!bEmptyText) {
          g2d.setColor(clrText);
          for (int i=0; i < lineCount; i++) {
            textLayout=((ChartTextMetrics)textMetrics).getLayout(i);
            if (bRightAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + dFullWidth - dWidth - insets.getRight();
            }
 else             if (bCenterAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + (dFullWidth - dWidth) / 2;
            }
            textLayout.draw(g2d,(float)(dX + dXOffset + insets.getLeft()),(float)(dY - dYHalfOffset + insets.getTop() + dHeight * (i + 1) - dDescent));
          }
        }
        renderOutline(renderer,label.getOutline(),r2d);
      }
    }
 else     if (dAngleInDegrees > 0 && dAngleInDegrees < 90) {
      double dDeltaX=dHeight * Math.sin(dAngleInRadians);
      double dDeltaY=dHeight * Math.cos(dAngleInRadians) - dHeight / 2;
      dX-=dDeltaX;
      dY+=dDeltaY;
      g2d.rotate(dAngleInRadians,iRotateX - dDeltaX,iRotateY + dDeltaY);
      dYDiff=dY - dFullHeight;
      if (bShadow) {
        g2d.setPaint(new GradientPaint(new Point2D.Double(dX + shadowness,dYDiff + shadowness),(Color)_sxs.getColor(label.getShadowColor()),new Point2D.Double(dX + shadowness + dFullWidth,dY + shadowness),(Color)_sxs.getColor(label.getShadowColor().translucent())));
        fillShadow(g2d,new Rectangle2D.Double(dX + shadowness,dYDiff + shadowness,dFullWidth,dFullHeight));
      }
 else {
        final Rectangle2D.Double r2d=new Rectangle2D.Double(dX,dYDiff,dFullWidth,dFullHeight);
        if (clrBackground != null) {
          g2d.setColor(clrBackground);
          g2d.fill(r2d);
        }
        if (!bEmptyText) {
          g2d.setColor(clrText);
          for (int i=0; i < lineCount; i++) {
            textLayout=((ChartTextMetrics)textMetrics).getLayout(i);
            if (bRightAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + dFullWidth - dWidth - insets.getRight();
            }
 else             if (bCenterAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + (dFullWidth - dWidth) / 2;
            }
            textLayout.draw(g2d,(float)(dX + dXOffset + insets.getLeft()),(float)((dY - dDescent + dHeight * i) + insets.getTop()));
          }
        }
        renderOutline(renderer,label.getOutline(),r2d);
      }
    }
 else     if (dAngleInDegrees < 0 && dAngleInDegrees > -90) {
      double dDeltaY=-dHeight / 2;
      dY+=dDeltaY;
      g2d.rotate(dAngleInRadians,iRotateX,iRotateY + dDeltaY);
      dYDiff=dY - dFullHeight;
      if (bShadow) {
        g2d.setPaint(new GradientPaint(new Point2D.Double(dX + shadowness,dYDiff + shadowness),(Color)_sxs.getColor(label.getShadowColor()),new Point2D.Double(dX + shadowness + dFullWidth,dY + shadowness),(Color)_sxs.getColor(label.getShadowColor().translucent())));
        fillShadow(g2d,new Rectangle2D.Double(dX + shadowness,dYDiff + shadowness,dFullWidth,dFullHeight));
      }
 else {
        final Rectangle2D.Double r2d=new Rectangle2D.Double(dX,dY - dFullHeight,dFullWidth,dFullHeight);
        if (clrBackground != null) {
          g2d.setColor(clrBackground);
          g2d.fill(r2d);
        }
        if (!bEmptyText) {
          g2d.setColor(clrText);
          for (int i=0; i < lineCount; i++) {
            textLayout=((ChartTextMetrics)textMetrics).getLayout(i);
            if (bRightAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + dFullWidth - dWidth - insets.getRight();
            }
 else             if (bCenterAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + (dFullWidth - dWidth) / 2;
            }
            textLayout.draw(g2d,(float)(dX + dXOffset + insets.getLeft()),(float)((dY - dDescent - dHeight * (lineCount - i - 1)) - insets.getBottom()));
          }
        }
        renderOutline(renderer,label.getOutline(),r2d);
      }
    }
 else     if (dAngleInDegrees == 90) {
      double dDeltaX=dHeight;
      double dDeltaY=(dFullWidth - dHeight) / 2;
      dX+=dDeltaX;
      dY+=dDeltaY;
      g2d.rotate(dAngleInRadians,dX,dY);
      dYDiff=dY - dFullHeight;
      if (bShadow) {
        g2d.setPaint(new GradientPaint(new Point2D.Double(dX + shadowness,dYDiff + shadowness),(Color)_sxs.getColor(label.getShadowColor()),new Point2D.Double(dX + shadowness + dFullWidth,dY + shadowness),(Color)_sxs.getColor(label.getShadowColor().translucent())));
        fillShadow(g2d,new Rectangle2D.Double(dX + shadowness,dYDiff + shadowness,dFullWidth,dFullHeight));
      }
 else {
        final Rectangle2D.Double r2d=new Rectangle2D.Double(dX,dYDiff,dFullWidth,dFullHeight);
        if (clrBackground != null) {
          g2d.setColor(clrBackground);
          g2d.fill(r2d);
        }
        if (!bEmptyText) {
          g2d.setColor(clrText);
          for (int i=0; i < lineCount; i++) {
            textLayout=((ChartTextMetrics)textMetrics).getLayout(i);
            if (bRightAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + dFullWidth - dWidth - insets.getRight();
            }
 else             if (bCenterAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + (dFullWidth - dWidth) / 2;
            }
            textLayout.draw(g2d,(float)(dX + dXOffset + insets.getLeft()),(float)((dY - dDescent + dHeight * i) + insets.getTop()));
          }
        }
        renderOutline(renderer,label.getOutline(),r2d);
      }
    }
 else     if (dAngleInDegrees == -90) {
      double dDeltaX=0;
      double dDeltaY=(dFullWidth + dHeight) / 2;
      dX+=dDeltaX;
      dY-=dDeltaY;
      g2d.rotate(dAngleInRadians,dX,dY);
      dYDiff=dY - dFullHeight;
      if (bShadow) {
        g2d.setPaint(new GradientPaint(new Point2D.Double(dX + shadowness,dYDiff + shadowness),(Color)_sxs.getColor(label.getShadowColor()),new Point2D.Double(dX + shadowness + dFullWidth,dY + shadowness),(Color)_sxs.getColor(label.getShadowColor().translucent())));
        fillShadow(g2d,new Rectangle2D.Double(dX + shadowness,dYDiff + shadowness,dFullWidth,dFullHeight));
      }
 else {
        final Rectangle2D.Double r2d=new Rectangle2D.Double(dX,dYDiff,dFullWidth,dFullHeight);
        if (clrBackground != null) {
          g2d.setColor(clrBackground);
          g2d.fill(r2d);
        }
        if (!bEmptyText) {
          g2d.setColor(clrText);
          for (int i=0; i < lineCount; i++) {
            textLayout=((ChartTextMetrics)textMetrics).getLayout(i);
            if (bRightAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + dFullWidth - dWidth - insets.getRight();
            }
 else             if (bCenterAligned) {
              dWidth=textLayout.getBounds().getWidth();
              dXOffset=-insets.getLeft() + (dFullWidth - dWidth) / 2;
            }
            textLayout.draw(g2d,(float)(dX + dXOffset + insets.getLeft()),(float)((dY - dDescent + dHeight * i) + insets.getTop()));
          }
        }
        renderOutline(renderer,label.getOutline(),r2d);
      }
    }
  }
  finally {
    g2d.setTransform(afTransform);
    cComp.recycleTextMetrics(textMetrics);
  }
}