Program: 31152
Project: 31152
Buggy source:
private static List<CanvasObject> new_build(Collection<Instance> pins,Graphics g){
  Map<Direction,List<Instance>> edge;
  edge=new HashMap<Direction,List<Instance>>();
  edge.put(Direction.EAST,new ArrayList<Instance>());
  edge.put(Direction.WEST,new ArrayList<Instance>());
  int MaxLeftLabelLength=0;
  int MaxRightLabelLength=0;
  int TextHeight=0;
  int TextAscent=0;
  int TextDescend=0;
  if (!pins.isEmpty()) {
    boolean hasgraph=true;
    JPanel panel;
    JFrame frame=null;
    if (g == null) {
      System.out.print("String_Node_Str");
      hasgraph=false;
      panel=new JPanel();
      frame=new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.add(panel);
      frame.setVisible(true);
      g=panel.getGraphics();
    }
    FontMetrics fm=g.getFontMetrics(DrawAttr.DEFAULT_FONT);
    TextHeight=fm.getHeight();
    TextAscent=fm.getAscent();
    TextDescend=fm.getDescent();
    for (    Instance pin : pins) {
      Direction pinEdge;
      Text label=new Text(0,0,pin.getAttributeValue(StdAttr.LABEL));
      int LabelWidth=fm.stringWidth(label.getText());
      if (pin.getAttributeValue(Pin.ATTR_TYPE)) {
        pinEdge=Direction.EAST;
        if (LabelWidth > MaxRightLabelLength)         MaxRightLabelLength=LabelWidth;
      }
 else {
        pinEdge=Direction.WEST;
        if (LabelWidth > MaxLeftLabelLength)         MaxLeftLabelLength=LabelWidth;
      }
      List<Instance> e=edge.get(pinEdge);
      e.add(pin);
    }
    if (!hasgraph) {
      frame.setVisible(false);
      frame.dispose();
    }
  }
  for (  Map.Entry<Direction,List<Instance>> entry : edge.entrySet()) {
    sortPinList(entry.getValue(),entry.getKey());
  }
  int numEast=edge.get(Direction.EAST).size();
  int numWest=edge.get(Direction.WEST).size();
  int maxVert=Math.max(numEast,numWest);
  int dy=((TextHeight + (TextHeight >> 2) + 5) / 10) * 10;
  int width=((MaxLeftLabelLength + MaxRightLabelLength + 35) / 10) * 10;
  int height=(maxVert > 0) ? maxVert * dy : 20;
  int sdy=(TextAscent - TextDescend) >> 1;
  int ax;
  int ay;
  if (numEast > 0) {
    ax=width;
    ay=10;
  }
 else   if (numWest > 0) {
    ax=0;
    ay=10;
  }
 else {
    ax=0;
    ay=0;
  }
  int rx=OFFS + (9 - (ax + 9) % 10);
  int ry=OFFS + (9 - (ay + 9) % 10);
  Rectangle rect=new Rectangle(rx,ry,width,height);
  rect.setValue(DrawAttr.STROKE_WIDTH,Integer.valueOf(2));
  List<CanvasObject> ret=new ArrayList<CanvasObject>();
  ret.add(rect);
  placePins(ret,edge.get(Direction.WEST),rx,ry + 10,0,dy,true,sdy);
  placePins(ret,edge.get(Direction.EAST),rx + width,ry + 10,0,dy,false,sdy);
  ret.add(new AppearanceAnchor(Location.create(rx + ax,ry + ay)));
  return ret;
}

Fixed version (ground truth):
private static List<CanvasObject> new_build(Collection<Instance> pins,Graphics g){
  Map<Direction,List<Instance>> edge;
  edge=new HashMap<Direction,List<Instance>>();
  edge.put(Direction.EAST,new ArrayList<Instance>());
  edge.put(Direction.WEST,new ArrayList<Instance>());
  int MaxLeftLabelLength=0;
  int MaxRightLabelLength=0;
  int TextHeight=0;
  int TextAscent=0;
  int TextDescend=0;
  if (!pins.isEmpty()) {
    boolean hasgraph=true;
    JPanel panel;
    JFrame frame=null;
    if (g == null) {
      hasgraph=false;
      panel=new JPanel();
      frame=new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.add(panel);
      frame.setVisible(true);
      g=panel.getGraphics();
    }
    FontMetrics fm=g.getFontMetrics(DrawAttr.DEFAULT_FONT);
    TextHeight=fm.getHeight();
    TextAscent=fm.getAscent();
    TextDescend=fm.getDescent();
    for (    Instance pin : pins) {
      Direction pinEdge;
      Text label=new Text(0,0,pin.getAttributeValue(StdAttr.LABEL));
      int LabelWidth=fm.stringWidth(label.getText());
      if (pin.getAttributeValue(Pin.ATTR_TYPE)) {
        pinEdge=Direction.EAST;
        if (LabelWidth > MaxRightLabelLength)         MaxRightLabelLength=LabelWidth;
      }
 else {
        pinEdge=Direction.WEST;
        if (LabelWidth > MaxLeftLabelLength)         MaxLeftLabelLength=LabelWidth;
      }
      List<Instance> e=edge.get(pinEdge);
      e.add(pin);
    }
    if (!hasgraph) {
      frame.setVisible(false);
      frame.dispose();
    }
  }
  for (  Map.Entry<Direction,List<Instance>> entry : edge.entrySet()) {
    sortPinList(entry.getValue(),entry.getKey());
  }
  int numEast=edge.get(Direction.EAST).size();
  int numWest=edge.get(Direction.WEST).size();
  int maxVert=Math.max(numEast,numWest);
  int dy=((TextHeight + (TextHeight >> 2) + 5) / 10) * 10;
  int width=((MaxLeftLabelLength + MaxRightLabelLength + 35) / 10) * 10;
  int height=(maxVert > 0) ? maxVert * dy : 20;
  int sdy=(TextAscent - TextDescend) >> 1;
  int ax;
  int ay;
  if (numEast > 0) {
    ax=width;
    ay=10;
  }
 else   if (numWest > 0) {
    ax=0;
    ay=10;
  }
 else {
    ax=0;
    ay=0;
  }
  int rx=OFFS + (9 - (ax + 9) % 10);
  int ry=OFFS + (9 - (ay + 9) % 10);
  Rectangle rect=new Rectangle(rx,ry,width,height);
  rect.setValue(DrawAttr.STROKE_WIDTH,Integer.valueOf(2));
  List<CanvasObject> ret=new ArrayList<CanvasObject>();
  ret.add(rect);
  placePins(ret,edge.get(Direction.WEST),rx,ry + 10,0,dy,true,sdy);
  placePins(ret,edge.get(Direction.EAST),rx + width,ry + 10,0,dy,false,sdy);
  ret.add(new AppearanceAnchor(Location.create(rx + ax,ry + ay)));
  return ret;
}