Program: 107958
Project: 107958
Buggy source:
public void layout(IFigure container){
  Rectangle area=container.getClientArea();
  if (scale != null && scale.isDirty()) {
    M=Math.max(FigureUtilities.getTextWidth(scale.format(scale.getRange().getLower()),scale.getFont()),FigureUtilities.getTextWidth(scale.format(scale.getRange().getUpper()),scale.getFont())) / 2;
  }
  int h=area.height;
  int w=area.width;
  int offsetY=0;
  int offsetX=0;
  if (h > HW_RATIO * (w - 2 * M)) {
    h=(int)(HW_RATIO * (w - 2 * M));
    offsetY=(area.height - h) / 2;
    if (offsetY > 10) {
      offsetY-=10;
    }
 else {
      offsetY=0;
    }
  }
 else {
    offsetX=((int)(HW_RATIO * (w - 2 * M)) - h);
  }
  double r=h / (1 - Math.sin(ALPHA) / 2);
  int x=(int)(area.x - r * (1.0 - Math.cos(ALPHA)) + M);
  int y=area.y;
  area=new Rectangle(x + offsetX,y + offsetY,(int)(2 * r),(int)(2 * r));
  Point center=area.getCenter();
  if (scale != null) {
    scale.setBounds(area);
  }
  if (ramp != null && ramp.isVisible()) {
    Rectangle rampBounds=area.getCopy();
    ramp.setBounds(rampBounds.shrink(area.width / 4 - ramp.getRampWidth(),area.height / 4 - ramp.getRampWidth()));
  }
  if (valueLabel != null) {
    Dimension labelSize=valueLabel.getPreferredSize();
    int lY1=area.y + area.height / 2 - (scale.getInnerRadius() - area.height / 5) / 2 - labelSize.height / 2;
    int lY2=container.getClientArea().height - labelSize.height + 3;
    valueLabel.setBounds(new Rectangle(area.x + area.width / 2 - labelSize.width / 2,Math.min(lY1,lY2),labelSize.width,labelSize.height));
  }
  if (needle != null && scale != null) {
    needlePoints.setPoint(new Point(center.x + area.width / 4,center.y - NEEDLE_WIDTH / 2 + 3),0);
    scale.getScaleTickMarks();
    needlePoints.setPoint(new Point(center.x + scale.getInnerRadius() - GAP_BTW_NEEDLE_SCALE,center.y),1);
    needlePoints.setPoint(new Point(center.x + area.width / 4,center.y + NEEDLE_WIDTH / 2 - 3),2);
    double valuePosition=360 - scale.getValuePosition(getCoercedValue(),false);
    if (maximum > minimum) {
      if (value > maximum)       valuePosition+=8;
 else       if (value < minimum)       valuePosition-=8;
    }
 else {
      if (value > minimum)       valuePosition-=8;
 else       if (value < maximum)       valuePosition+=8;
    }
    needlePoints.setPoint(PointsUtil.rotate(needlePoints.getPoint(0),valuePosition,center),0);
    needlePoints.setPoint(PointsUtil.rotate(needlePoints.getPoint(1),valuePosition,center),1);
    needlePoints.setPoint(PointsUtil.rotate(needlePoints.getPoint(2),valuePosition,center),2);
    needle.setPoints(needlePoints);
  }
}

Fixed version (ground truth):
public void layout(IFigure container){
  Rectangle area=container.getClientArea();
  if (scale != null && scale.isDirty()) {
    M=Math.max(FigureUtilities.getTextWidth(scale.format(scale.getRange().getLower()),scale.getFont()),FigureUtilities.getTextWidth(scale.format(scale.getRange().getUpper()),scale.getFont())) / 2;
  }
  int h=area.height;
  int w=area.width;
  int offsetY=0;
  int offsetX=0;
  if (h > HW_RATIO * (w - 2 * M)) {
    h=(int)(HW_RATIO * (w - 2 * M));
    offsetY=(area.height - h) / 2;
    if (offsetY > 10) {
      offsetY-=10;
    }
 else {
      offsetY=0;
    }
  }
 else {
    offsetX=((int)(HW_RATIO * (w - 2 * M)) - h);
  }
  double r=h / (1 - Math.sin(ALPHA) / 2);
  int x=(int)(area.x - r * (1.0 - Math.cos(ALPHA)) + M);
  int y=area.y;
  area=new Rectangle(x + offsetX,y + offsetY,(int)(2 * r),(int)(2 * r));
  Point center=area.getCenter();
  if (scale != null) {
    scale.setBounds(area);
  }
  if (ramp != null && ramp.isVisible()) {
    Rectangle rampBounds=area.getCopy();
    ramp.setBounds(rampBounds.shrink(area.width / 4 - ramp.getRampWidth(),area.height / 4 - ramp.getRampWidth()));
  }
  if (valueLabel != null) {
    Dimension labelSize=valueLabel.getPreferredSize();
    int lY1=area.y + area.height / 2 - (scale.getInnerRadius() - area.height / 5) / 2 - labelSize.height / 2;
    int lY2=container.getClientArea().height - labelSize.height - 3;
    valueLabel.setBounds(new Rectangle(area.x + area.width / 2 - labelSize.width / 2,Math.min(lY1,lY2),labelSize.width,labelSize.height));
  }
  if (needle != null && scale != null) {
    needlePoints.setPoint(new Point(center.x + area.width / 4,center.y - NEEDLE_WIDTH / 2 + 3),0);
    scale.getScaleTickMarks();
    needlePoints.setPoint(new Point(center.x + scale.getInnerRadius() - GAP_BTW_NEEDLE_SCALE,center.y),1);
    needlePoints.setPoint(new Point(center.x + area.width / 4,center.y + NEEDLE_WIDTH / 2 - 3),2);
    double valuePosition=360 - scale.getValuePosition(getCoercedValue(),false);
    if (maximum > minimum) {
      if (value > maximum)       valuePosition+=8;
 else       if (value < minimum)       valuePosition-=8;
    }
 else {
      if (value > minimum)       valuePosition-=8;
 else       if (value < maximum)       valuePosition+=8;
    }
    needlePoints.setPoint(PointsUtil.rotate(needlePoints.getPoint(0),valuePosition,center),0);
    needlePoints.setPoint(PointsUtil.rotate(needlePoints.getPoint(1),valuePosition,center),1);
    needlePoints.setPoint(PointsUtil.rotate(needlePoints.getPoint(2),valuePosition,center),2);
    needle.setPoints(needlePoints);
  }
}