Program: 163951
Project: 163951
Buggy source:
protected static Rect findFreeSpace(Point start,ArrayList<Room> collision,int maxSize){
  Rect space=new Rect(start.x - maxSize,start.y - maxSize,start.x + maxSize,start.y + maxSize);
  ArrayList<Room> colliding=new ArrayList<>(collision);
  do {
    Iterator<Room> it=colliding.iterator();
    while (it.hasNext()) {
      Room room=it.next();
      if (Math.max(space.left,room.left) >= Math.min(space.right,room.right) || Math.max(space.top,room.top) >= Math.min(space.bottom,room.bottom)) {
        it.remove();
      }
    }
    Room closestRoom=null;
    int closestDiff=Integer.MAX_VALUE;
    boolean inside=true;
    int curDiff=0;
    for (    Room curRoom : colliding) {
      if (start.x <= curRoom.left) {
        inside=false;
        curDiff+=curRoom.left - start.x;
      }
 else       if (start.x >= curRoom.right) {
        inside=false;
        curDiff+=start.x - curRoom.right;
      }
      if (start.y <= curRoom.top) {
        inside=false;
        curDiff+=curRoom.top - start.y;
      }
 else       if (start.y >= curRoom.bottom) {
        inside=false;
        curDiff+=start.y - curRoom.bottom;
      }
      if (inside) {
        space.set(start.x,start.y,start.x,start.y);
        return space;
      }
      if (curDiff < closestDiff) {
        closestDiff=curDiff;
        closestRoom=curRoom;
      }
    }
    int wDiff, hDiff;
    if (closestRoom != null) {
      wDiff=Integer.MAX_VALUE;
      if (closestRoom.left >= start.x) {
        wDiff=(space.right - closestRoom.left) * (space.height() + 1);
      }
 else       if (closestRoom.right <= start.x) {
        wDiff=(closestRoom.right - space.left) * (space.height() + 1);
      }
      hDiff=Integer.MAX_VALUE;
      if (closestRoom.top >= start.y) {
        hDiff=(space.bottom - closestRoom.top) * (space.width() + 1);
      }
 else       if (closestRoom.bottom <= start.y) {
        hDiff=(closestRoom.bottom - space.top) * (space.width() + 1);
      }
      if (wDiff < hDiff || wDiff == hDiff && Random.Int(2) == 0) {
        if (closestRoom.left >= start.x && closestRoom.left < space.right)         space.right=closestRoom.left;
        if (closestRoom.right <= start.x && closestRoom.right > space.left)         space.left=closestRoom.right;
      }
 else {
        if (closestRoom.top >= start.y && closestRoom.top < space.bottom)         space.bottom=closestRoom.top;
        if (closestRoom.bottom <= start.y && closestRoom.bottom > space.top)         space.top=closestRoom.bottom;
      }
      colliding.remove(closestRoom);
    }
 else {
      colliding.clear();
    }
  }
 while (!colliding.isEmpty());
  return space;
}

Fixed version (ground truth):
protected static Rect findFreeSpace(Point start,ArrayList<Room> collision,int maxSize){
  Rect space=new Rect(start.x - maxSize,start.y - maxSize,start.x + maxSize,start.y + maxSize);
  ArrayList<Room> colliding=new ArrayList<>(collision);
  do {
    Iterator<Room> it=colliding.iterator();
    while (it.hasNext()) {
      Room room=it.next();
      if (room.isEmpty() || Math.max(space.left,room.left) >= Math.min(space.right,room.right) || Math.max(space.top,room.top) >= Math.min(space.bottom,room.bottom)) {
        it.remove();
      }
    }
    Room closestRoom=null;
    int closestDiff=Integer.MAX_VALUE;
    boolean inside=true;
    int curDiff=0;
    for (    Room curRoom : colliding) {
      if (start.x <= curRoom.left) {
        inside=false;
        curDiff+=curRoom.left - start.x;
      }
 else       if (start.x >= curRoom.right) {
        inside=false;
        curDiff+=start.x - curRoom.right;
      }
      if (start.y <= curRoom.top) {
        inside=false;
        curDiff+=curRoom.top - start.y;
      }
 else       if (start.y >= curRoom.bottom) {
        inside=false;
        curDiff+=start.y - curRoom.bottom;
      }
      if (inside) {
        space.set(start.x,start.y,start.x,start.y);
        return space;
      }
      if (curDiff < closestDiff) {
        closestDiff=curDiff;
        closestRoom=curRoom;
      }
    }
    int wDiff, hDiff;
    if (closestRoom != null) {
      wDiff=Integer.MAX_VALUE;
      if (closestRoom.left >= start.x) {
        wDiff=(space.right - closestRoom.left) * (space.height() + 1);
      }
 else       if (closestRoom.right <= start.x) {
        wDiff=(closestRoom.right - space.left) * (space.height() + 1);
      }
      hDiff=Integer.MAX_VALUE;
      if (closestRoom.top >= start.y) {
        hDiff=(space.bottom - closestRoom.top) * (space.width() + 1);
      }
 else       if (closestRoom.bottom <= start.y) {
        hDiff=(closestRoom.bottom - space.top) * (space.width() + 1);
      }
      if (wDiff < hDiff || wDiff == hDiff && Random.Int(2) == 0) {
        if (closestRoom.left >= start.x && closestRoom.left < space.right)         space.right=closestRoom.left;
        if (closestRoom.right <= start.x && closestRoom.right > space.left)         space.left=closestRoom.right;
      }
 else {
        if (closestRoom.top >= start.y && closestRoom.top < space.bottom)         space.bottom=closestRoom.top;
        if (closestRoom.bottom <= start.y && closestRoom.bottom > space.top)         space.top=closestRoom.bottom;
      }
      colliding.remove(closestRoom);
    }
 else {
      colliding.clear();
    }
  }
 while (!colliding.isEmpty());
  return space;
}