Program: 74737
Project: 74737
Buggy source:
private Polyline2D _route(Point2D head,int headDir,Point2D tail,int tailDir){
  double xDiff=head.getX() - tail.getX();
  double yDiff=head.getY() - tail.getY();
  Point2D point;
  int dir;
  if (((xDiff * xDiff) < (TOL * TOL)) && ((yDiff * yDiff) < (TOL * TOL))) {
    Polyline2D route=new Polyline2D.Double();
    route.moveTo(tail.getX(),tail.getY());
    return route;
  }
  if (headDir == SwingUtilities.WEST) {
    if ((xDiff > 0) && ((yDiff * yDiff) < TOL) && (tailDir == SwingUtilities.EAST)) {
      point=tail;
      dir=tailDir;
    }
 else {
      if (xDiff < 0) {
        point=new Point2D.Double(head.getX() - MINDIST,head.getY());
      }
 else       if (((yDiff > 0) && (tailDir == SwingUtilities.SOUTH)) || ((yDiff < 0) && (tailDir == SwingUtilities.NORTH))) {
        point=new Point2D.Double(tail.getX(),head.getY());
      }
 else       if (headDir == tailDir) {
        double pos=Math.min(head.getX(),tail.getX()) - MINDIST;
        point=new Point2D.Double(pos,head.getY());
      }
 else {
        point=new Point2D.Double(head.getX() - (xDiff / 2),head.getY());
      }
      if (yDiff > 0) {
        dir=SwingUtilities.NORTH;
      }
 else {
        dir=SwingUtilities.SOUTH;
      }
    }
  }
 else   if (headDir == SwingUtilities.EAST) {
    if ((xDiff < 0) && ((yDiff * yDiff) < TOL) && (tailDir == SwingUtilities.WEST)) {
      point=tail;
      dir=tailDir;
    }
 else {
      if (xDiff > 0) {
        point=new Point2D.Double(head.getX() + MINDIST,head.getY());
      }
 else       if (((yDiff > 0) && (tailDir == SwingUtilities.SOUTH)) || ((yDiff < 0) && (tailDir == SwingUtilities.NORTH))) {
        point=new Point2D.Double(tail.getX(),head.getY());
      }
 else       if (headDir == tailDir) {
        double pos=Math.max(head.getX(),tail.getX()) + MINDIST;
        point=new Point2D.Double(pos,head.getY());
      }
 else {
        point=new Point2D.Double(head.getX() - (xDiff / 2),head.getY());
      }
      if (yDiff > 0) {
        dir=SwingUtilities.NORTH;
      }
 else {
        dir=SwingUtilities.SOUTH;
      }
    }
  }
 else   if (headDir == SwingUtilities.SOUTH) {
    if (((xDiff * xDiff) < TOL) && (yDiff < 0) && (tailDir == SwingUtilities.NORTH)) {
      point=tail;
      dir=tailDir;
    }
 else {
      if (yDiff > 0) {
        point=new Point2D.Double(head.getX(),head.getY() + MINDIST);
      }
 else       if (((xDiff > 0) && (tailDir == SwingUtilities.EAST)) || ((xDiff < 0) && (tailDir == SwingUtilities.WEST))) {
        point=new Point2D.Double(head.getX(),tail.getY());
      }
 else       if (headDir == tailDir) {
        double pos=Math.max(head.getY(),tail.getY()) + MINDIST;
        point=new Point2D.Double(head.getX(),pos);
      }
 else {
        point=new Point2D.Double(head.getX(),head.getY() - (yDiff / 2));
      }
      if (xDiff > 0) {
        dir=SwingUtilities.WEST;
      }
 else {
        dir=SwingUtilities.EAST;
      }
    }
  }
 else   if (headDir == SwingUtilities.NORTH) {
    if (((xDiff * xDiff) < TOL) && (yDiff > 0) && (tailDir == SwingUtilities.SOUTH)) {
      point=tail;
      dir=tailDir;
    }
 else {
      if (yDiff < 0) {
        point=new Point2D.Double(head.getX(),head.getY() - MINDIST);
      }
 else       if (((xDiff > 0) && (tailDir == SwingUtilities.EAST)) || ((xDiff < 0) && (tailDir == SwingUtilities.WEST))) {
        point=new Point2D.Double(head.getX(),tail.getY());
      }
 else       if (headDir == tailDir) {
        double pos=Math.min(head.getY(),tail.getY()) - MINDIST;
        point=new Point2D.Double(head.getX(),pos);
      }
 else {
        point=new Point2D.Double(head.getX(),head.getY() - (yDiff / 2));
      }
      if (xDiff > 0) {
        dir=SwingUtilities.WEST;
      }
 else {
        dir=SwingUtilities.EAST;
      }
    }
  }
 else {
    throw new RuntimeException("String_Node_Str");
  }
  Polyline2D route=_route(point,dir,tail,tailDir);
  route.lineTo(head.getX(),head.getY());
  return route;
}

Fixed version (ground truth):
private Polyline2D _route(Point2D head,int headDir,Point2D tail,int tailDir){
  double xDiff=head.getX() - tail.getX();
  double yDiff=head.getY() - tail.getY();
  Point2D point;
  int dir;
  if (((xDiff * xDiff) < (TOL * TOL)) && ((yDiff * yDiff) < (TOL * TOL))) {
    Polyline2D route=new Polyline2D.Double();
    route.moveTo(tail.getX(),tail.getY());
    return route;
  }
  if (headDir == SwingConstants.WEST) {
    if ((xDiff > 0) && ((yDiff * yDiff) < TOL) && (tailDir == SwingConstants.EAST)) {
      point=tail;
      dir=tailDir;
    }
 else {
      if (xDiff < 0) {
        point=new Point2D.Double(head.getX() - MINDIST,head.getY());
      }
 else       if (((yDiff > 0) && (tailDir == SwingConstants.SOUTH)) || ((yDiff < 0) && (tailDir == SwingConstants.NORTH))) {
        point=new Point2D.Double(tail.getX(),head.getY());
      }
 else       if (headDir == tailDir) {
        double pos=Math.min(head.getX(),tail.getX()) - MINDIST;
        point=new Point2D.Double(pos,head.getY());
      }
 else {
        point=new Point2D.Double(head.getX() - (xDiff / 2),head.getY());
      }
      if (yDiff > 0) {
        dir=SwingConstants.NORTH;
      }
 else {
        dir=SwingConstants.SOUTH;
      }
    }
  }
 else   if (headDir == SwingConstants.EAST) {
    if ((xDiff < 0) && ((yDiff * yDiff) < TOL) && (tailDir == SwingConstants.WEST)) {
      point=tail;
      dir=tailDir;
    }
 else {
      if (xDiff > 0) {
        point=new Point2D.Double(head.getX() + MINDIST,head.getY());
      }
 else       if (((yDiff > 0) && (tailDir == SwingConstants.SOUTH)) || ((yDiff < 0) && (tailDir == SwingConstants.NORTH))) {
        point=new Point2D.Double(tail.getX(),head.getY());
      }
 else       if (headDir == tailDir) {
        double pos=Math.max(head.getX(),tail.getX()) + MINDIST;
        point=new Point2D.Double(pos,head.getY());
      }
 else {
        point=new Point2D.Double(head.getX() - (xDiff / 2),head.getY());
      }
      if (yDiff > 0) {
        dir=SwingConstants.NORTH;
      }
 else {
        dir=SwingConstants.SOUTH;
      }
    }
  }
 else   if (headDir == SwingConstants.SOUTH) {
    if (((xDiff * xDiff) < TOL) && (yDiff < 0) && (tailDir == SwingConstants.NORTH)) {
      point=tail;
      dir=tailDir;
    }
 else {
      if (yDiff > 0) {
        point=new Point2D.Double(head.getX(),head.getY() + MINDIST);
      }
 else       if (((xDiff > 0) && (tailDir == SwingConstants.EAST)) || ((xDiff < 0) && (tailDir == SwingConstants.WEST))) {
        point=new Point2D.Double(head.getX(),tail.getY());
      }
 else       if (headDir == tailDir) {
        double pos=Math.max(head.getY(),tail.getY()) + MINDIST;
        point=new Point2D.Double(head.getX(),pos);
      }
 else {
        point=new Point2D.Double(head.getX(),head.getY() - (yDiff / 2));
      }
      if (xDiff > 0) {
        dir=SwingConstants.WEST;
      }
 else {
        dir=SwingConstants.EAST;
      }
    }
  }
 else   if (headDir == SwingConstants.NORTH) {
    if (((xDiff * xDiff) < TOL) && (yDiff > 0) && (tailDir == SwingConstants.SOUTH)) {
      point=tail;
      dir=tailDir;
    }
 else {
      if (yDiff < 0) {
        point=new Point2D.Double(head.getX(),head.getY() - MINDIST);
      }
 else       if (((xDiff > 0) && (tailDir == SwingConstants.EAST)) || ((xDiff < 0) && (tailDir == SwingConstants.WEST))) {
        point=new Point2D.Double(head.getX(),tail.getY());
      }
 else       if (headDir == tailDir) {
        double pos=Math.min(head.getY(),tail.getY()) - MINDIST;
        point=new Point2D.Double(head.getX(),pos);
      }
 else {
        point=new Point2D.Double(head.getX(),head.getY() - (yDiff / 2));
      }
      if (xDiff > 0) {
        dir=SwingConstants.WEST;
      }
 else {
        dir=SwingConstants.EAST;
      }
    }
  }
 else {
    throw new RuntimeException("String_Node_Str");
  }
  Polyline2D route=_route(point,dir,tail,tailDir);
  route.lineTo(head.getX(),head.getY());
  return route;
}