Program: 13653
Project: 13653
Buggy source:
@Override protected void paintComponent(Graphics g){
  g.setColor(Color.WHITE);
  g.fillRect(0,0,getWidth(),getHeight());
  g.setColor(Color.BLACK);
  if (g instanceof Graphics2D) {
    ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  }
  double yStart, xStart;
  if (minY % yInterval == 0) {
    yStart=minY;
  }
 else {
    yStart=yInterval * (((int)minY / yInterval) + 1);
  }
  if (minX % xInterval == 0) {
    xStart=minX;
  }
 else {
    xStart=xInterval * (((int)minX / xInterval) + 1);
  }
  int xOffset=0;
  int yLabelRightShift=12;
  if (yLabel == null || yLabel.isEmpty()) {
    yLabelRightShift=0;
  }
 else {
    if (g instanceof Graphics2D) {
      Graphics2D g2=(Graphics2D)g;
      AffineTransform orig=g2.getTransform();
      g2.rotate(-Math.PI / 2);
      g2.setColor(Color.BLACK);
      g2.drawString(yLabel,-getY(-yInterval) / 2 - (g.getFontMetrics().stringWidth(yLabel) / 2),yLabelRightShift);
      g2.setTransform(orig);
    }
  }
  int lastYLabelEnd=Integer.MAX_VALUE;
  for (double i=yStart; i <= maxY; i+=yInterval) {
    String label="String_Node_Str" + i;
    label=label.replaceAll("String_Node_Str","String_Node_Str");
    int width=g.getFontMetrics().stringWidth(label);
    if (width > xOffset) {
      xOffset=width;
    }
    int baseNumberHeight=g.getFontMetrics().getHeight();
    int baseNumberPosition=getY(i) + (baseNumberHeight / 2);
    if (baseNumberPosition + baseNumberHeight < lastYLabelEnd) {
      g.drawString(label,yLabelRightShift + 6,baseNumberPosition);
      lastYLabelEnd=baseNumberPosition + 2;
    }
  }
  xOffset=xOffset + yLabelRightShift + 8;
  g.setColor(new Color(180,180,180));
  for (double i=yStart; i <= maxY; i+=yInterval) {
    g.drawLine(xOffset,getY(i),getWidth() - 10,getY(i));
  }
  g.setColor(Color.BLACK);
  int titleWidth=g.getFontMetrics().stringWidth(graphTitle);
  g.drawString(graphTitle,(xOffset + ((getWidth() - (xOffset + 10)) / 2)) - (titleWidth / 2),30);
  g.drawString(xLabel,(getWidth() / 2) - (g.getFontMetrics().stringWidth(xLabel) / 2),getHeight() - 5);
  double baseWidth=(getWidth() - (xOffset + 10)) / (maxX - minX);
  int lastXLabelEnd=0;
  for (double i=xStart; i <= maxX; i+=xInterval) {
    g.setColor(Color.BLACK);
    String baseNumber="String_Node_Str" + i;
    baseNumber=baseNumber.replaceAll("String_Node_Str","String_Node_Str");
    int baseNumberWidth=g.getFontMetrics().stringWidth(baseNumber);
    int baseNumberPosition=(int)(xOffset + (baseWidth * i) - (baseNumberWidth / 2));
    if (baseNumberPosition > lastXLabelEnd) {
      g.drawString(baseNumber,baseNumberPosition,getHeight() - 25);
      lastXLabelEnd=baseNumberPosition + baseNumberWidth + 5;
    }
    g.setColor(new Color(180,180,180));
    g.drawLine((int)(xOffset + (baseWidth * i)),getHeight() - 40,(int)(xOffset + (baseWidth * i)),40);
    g.setColor(Color.BLACK);
  }
  g.drawLine(xOffset,getHeight() - 40,getWidth() - 10,getHeight() - 40);
  g.drawLine(xOffset,getHeight() - 40,xOffset,40);
  rectangles=new ArrayList<Rectangle>();
  tips=new ArrayList<String>();
  g.setColor(Color.BLUE);
  double ovalSize=5;
  double[] inputVar=new double[data.length];
  double[] responseVar=new double[data.length];
  for (int d=0; d < data.length; d++) {
    double x=getX(xCategories[d],xOffset) - ovalSize / 2;
    double y=getY(data[d]) - ovalSize / 2;
    g.fillOval((int)x,(int)y,(int)(ovalSize),(int)(ovalSize));
    inputVar[d]=Double.valueOf(xCategories[d]);
    responseVar[d]=data[d];
    Rectangle r=new Rectangle((int)x,(int)y,(int)(ovalSize),(int)(ovalSize));
    rectangles.add(r);
    tips.add(toolTipLabels[d]);
  }
  g.setColor(Color.BLACK);
  if (data.length > 1) {
    LinearRegression linReg=new LinearRegression(inputVar,responseVar);
    double intercept=linReg.intercept();
    double slope=linReg.slope();
    double rSquare=linReg.R2();
    double x1=minX;
    double y1=slope * minX + intercept;
    if (y1 < minY) {
      x1=(minY - intercept) / slope;
      y1=minY;
    }
 else     if (y1 > maxY) {
      x1=(maxY - intercept) / slope;
      y1=maxY;
    }
    double xn=maxX;
    double yn=slope * maxX + intercept;
    if (g instanceof Graphics2D) {
      ((Graphics2D)g).setStroke(new BasicStroke(1.5f));
    }
    g.setColor(Color.RED);
    g.drawLine(getX(x1,xOffset),getY(y1),getX(xn,xOffset),getY(yn));
    g.setColor(Color.BLACK);
    if (g instanceof Graphics2D) {
      ((Graphics2D)g).setStroke(new BasicStroke(1));
    }
    String legendString="String_Node_Str" + Precision.round(slope,3) + "String_Node_Str";
    if (intercept < 0)     legendString+="String_Node_Str" + Precision.round(-intercept,3);
 else     legendString+="String_Node_Str" + Precision.round(intercept,3);
    int width=g.getFontMetrics().stringWidth(legendString);
    g.setColor(Color.WHITE);
    g.fillRect(xOffset + 10,45,width + 8,35);
    g.setColor(Color.LIGHT_GRAY);
    g.drawRect(xOffset + 10,45,width + 8,35);
    g.setColor(Color.RED);
    g.drawString(legendString,xOffset + 13,60);
    g.drawString("String_Node_Str" + Precision.round(rSquare,3),xOffset + 13,76);
    g.setColor(Color.BLACK);
  }
}

Fixed version (ground truth):
@Override protected void paintComponent(Graphics g){
  g.setColor(Color.WHITE);
  g.fillRect(0,0,getWidth(),getHeight());
  g.setColor(Color.BLACK);
  if (g instanceof Graphics2D) {
    ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  }
  double yStart, xStart;
  if (minY % yInterval == 0) {
    yStart=minY;
  }
 else {
    yStart=yInterval * (((int)minY / yInterval) + 1);
  }
  if (minX % xInterval == 0) {
    xStart=minX;
  }
 else {
    xStart=xInterval * (((int)minX / xInterval) + 1);
  }
  int xOffset=0;
  int yLabelRightShift=12;
  if (yLabel == null || yLabel.isEmpty()) {
    yLabelRightShift=0;
  }
 else {
    if (g instanceof Graphics2D) {
      Graphics2D g2=(Graphics2D)g;
      AffineTransform orig=g2.getTransform();
      g2.rotate(-Math.PI / 2);
      g2.setColor(Color.BLACK);
      g2.drawString(yLabel,-getY(-yInterval) / 2 - (g.getFontMetrics().stringWidth(yLabel) / 2),yLabelRightShift);
      g2.setTransform(orig);
    }
  }
  int lastYLabelEnd=Integer.MAX_VALUE;
  for (double i=yStart; i <= maxY; i+=yInterval) {
    String label="String_Node_Str" + i;
    label=label.replaceAll("String_Node_Str","String_Node_Str");
    int width=g.getFontMetrics().stringWidth(label);
    if (width > xOffset) {
      xOffset=width;
    }
    int baseNumberHeight=g.getFontMetrics().getHeight();
    int baseNumberPosition=getY(i) + (baseNumberHeight / 2);
    if (baseNumberPosition + baseNumberHeight < lastYLabelEnd) {
      g.drawString(label,yLabelRightShift + 6,baseNumberPosition);
      lastYLabelEnd=baseNumberPosition + 2;
    }
  }
  xOffset=xOffset + yLabelRightShift + 8;
  g.setColor(new Color(180,180,180));
  for (double i=yStart; i <= maxY; i+=yInterval) {
    g.drawLine(xOffset,getY(i),getWidth() - 10,getY(i));
  }
  g.setColor(Color.BLACK);
  int titleWidth=g.getFontMetrics().stringWidth(graphTitle);
  g.drawString(graphTitle,(xOffset + ((getWidth() - (xOffset + 10)) / 2)) - (titleWidth / 2),30);
  g.drawString(xLabel,(getWidth() / 2) - (g.getFontMetrics().stringWidth(xLabel) / 2),getHeight() - 5);
  double baseWidth=(getWidth() - (xOffset + 10)) / (maxX - minX);
  int lastXLabelEnd=0;
  for (double i=xStart; i <= maxX; i+=xInterval) {
    g.setColor(Color.BLACK);
    String baseNumber="String_Node_Str" + i;
    baseNumber=baseNumber.replaceAll("String_Node_Str","String_Node_Str");
    int baseNumberWidth=g.getFontMetrics().stringWidth(baseNumber);
    int baseNumberPosition=(int)(xOffset + (baseWidth * i) - (baseNumberWidth / 2));
    if (baseNumberPosition > lastXLabelEnd) {
      g.drawString(baseNumber,baseNumberPosition,getHeight() - 25);
      lastXLabelEnd=baseNumberPosition + baseNumberWidth + 5;
    }
    g.setColor(new Color(180,180,180));
    g.drawLine((int)(xOffset + (baseWidth * i)),getHeight() - 40,(int)(xOffset + (baseWidth * i)),40);
    g.setColor(Color.BLACK);
  }
  g.drawLine(xOffset,getHeight() - 40,getWidth() - 10,getHeight() - 40);
  g.drawLine(xOffset,getHeight() - 40,xOffset,40);
  rectangles=new ArrayList<Rectangle>();
  tips=new ArrayList<String>();
  g.setColor(Color.BLUE);
  double ovalSize=5;
  double[] inputVar=new double[data.length];
  double[] responseVar=new double[data.length];
  for (int d=0; d < data.length; d++) {
    double x=getX(xCategories[d],xOffset) - ovalSize / 2;
    double y=getY(data[d]) - ovalSize / 2;
    g.fillOval((int)x,(int)y,(int)(ovalSize),(int)(ovalSize));
    g.drawString(toolTipLabels[d],(int)x + 2,(int)y + 16);
    inputVar[d]=Double.valueOf(xCategories[d]);
    responseVar[d]=data[d];
    Rectangle r=new Rectangle((int)x,(int)y,(int)(ovalSize),(int)(ovalSize));
    rectangles.add(r);
    tips.add(toolTipLabels[d]);
  }
  g.setColor(Color.BLACK);
  if (data.length > 1) {
    LinearRegression linReg=new LinearRegression(inputVar,responseVar);
    double intercept=linReg.intercept();
    double slope=linReg.slope();
    double rSquare=linReg.R2();
    double x1=minX;
    double y1=slope * minX + intercept;
    if (y1 < minY) {
      x1=(minY - intercept) / slope;
      y1=minY;
    }
 else     if (y1 > maxY) {
      x1=(maxY - intercept) / slope;
      y1=maxY;
    }
    double xn=maxX;
    double yn=slope * maxX + intercept;
    if (g instanceof Graphics2D) {
      ((Graphics2D)g).setStroke(new BasicStroke(1.5f));
    }
    g.setColor(Color.RED);
    g.drawLine(getX(x1,xOffset),getY(y1),getX(xn,xOffset),getY(yn));
    g.setColor(Color.BLACK);
    if (g instanceof Graphics2D) {
      ((Graphics2D)g).setStroke(new BasicStroke(1));
    }
    String legendString="String_Node_Str" + Precision.round(slope,3) + "String_Node_Str";
    if (intercept < 0)     legendString+="String_Node_Str" + Precision.round(-intercept,3);
 else     legendString+="String_Node_Str" + Precision.round(intercept,3);
    int width=g.getFontMetrics().stringWidth(legendString);
    g.setColor(Color.WHITE);
    g.fillRect(xOffset + 10,45,width + 8,35);
    g.setColor(Color.LIGHT_GRAY);
    g.drawRect(xOffset + 10,45,width + 8,35);
    g.setColor(Color.RED);
    g.drawString(legendString,xOffset + 13,60);
    g.drawString("String_Node_Str" + Precision.round(rSquare,3),xOffset + 13,76);
    g.setColor(Color.BLACK);
  }
}