Program: 184148
Project: 184148
Buggy source:
/** 
 * Allows someone to consume pixels from this polygon. There are some edge cases where the requested number of points my not have actually been consumed if the expansion outward from the selected start point encounter problems. I'm trying to remove this annoyance, but for now that means that this method should be called in a loop, checking if the desired area was received.
 * @param amountOfArea the number of pixels desired. If this is greater than the size of this polygon, all polygon pixels are returned and this poly will deregister itself from the area
 * @param startPoint The point at which the merge will start. If the caller is positive that they will consume this entire polygon, then this can be null
 * @return all of the points that can be consumed, up toMath.min(amountOfArea,size). The caller should check the size to see if it got what it requested
 */
public Collection<Point> consumeArea(int amountOfArea,Point startPoint){
  log.entering(className,"String_Node_Str",new Object[]{amountOfArea,startPoint});
  if (amountOfArea >= getArea()) {
    mRegionManager.removeRegion(this);
    log.exiting(className,"String_Node_Str","String_Node_Str");
    return mPoints;
  }
  List<Point> consumablePoints=new ArrayList<Point>(amountOfArea + 8);
  Set<Point> consumablePointsCopy=new HashSet<Point>(amountOfArea + 8);
  if (isConsumable(startPoint.x,startPoint.y,null)) {
    log.finest("String_Node_Str");
    consumablePoints.add(startPoint);
  }
 else {
    log.info("String_Node_Str");
    log.exiting(className,"String_Node_Str");
    return consumablePoints;
  }
  BufferedImage image=mRegionManager.getDebugImage(this);
  Graphics g=image.getGraphics();
  Point lastCur=null;
  int imageID=0;
  boolean debug=true;
  int i=0;
  int lastIterationListSize=0;
  Point cur=null;
  while (consumablePoints.size() < amountOfArea) {
    try {
      cur=consumablePoints.get(i);
    }
 catch (    IndexOutOfBoundsException ide) {
      if (lastIterationListSize == consumablePoints.size()) {
        mPoints.removeAll(consumablePoints);
        assert(isContigious());
        return consumablePoints;
      }
      log.finest("String_Node_Str");
      i=0;
      cur=consumablePoints.get(i);
      lastIterationListSize=consumablePoints.size();
    }
    if (cur == lastCur) {
    }
 else {
      StringBuilder name=new StringBuilder("String_Node_Str");
      if (imageID < 10)       name.append("String_Node_Str").append(imageID).append("String_Node_Str");
 else       if (imageID > 9 && imageID < 100)       name.append("String_Node_Str").append(imageID).append("String_Node_Str");
 else       if (imageID > 99 && imageID < 1000)       name.append("String_Node_Str").append(imageID).append("String_Node_Str");
 else       name.append(imageID).append("String_Node_Str");
      try {
        File f=new File(name.toString());
        ImageIO.write(image,"String_Node_Str",f);
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
      image=mRegionManager.getDebugImage(this);
      g=image.getGraphics();
      g.setColor(Color.GREEN);
      for (      Point p : consumablePoints)       g.drawLine(p.x,p.y,p.x,p.y);
      g.setColor(Color.RED);
      g.drawLine(cur.x,cur.y,cur.x,cur.y);
      lastCur=cur;
      imageID++;
    }
    g.setColor(Color.YELLOW);
    log.finest("String_Node_Str" + cur + "String_Node_Str");
    if (isConsumable(cur.x,cur.y - 1,consumablePointsCopy)) {
      consumablePoints.add(new Point(cur.x,cur.y - 1));
      consumablePointsCopy.add(consumablePoints.get(consumablePoints.size() - 1));
      if (debug)       g.drawLine(cur.x,cur.y - 1,cur.x,cur.y - 1);
      i=0;
      continue;
    }
    if (isConsumable(cur.x + 1,cur.y,consumablePointsCopy)) {
      consumablePoints.add(new Point(cur.x + 1,cur.y));
      consumablePointsCopy.add(consumablePoints.get(consumablePoints.size() - 1));
      if (debug)       g.drawLine(cur.x + 1,cur.y,cur.x + 1,cur.y);
      i=0;
      continue;
    }
    if (isConsumable(cur.x,cur.y + 1,consumablePointsCopy)) {
      consumablePoints.add(new Point(cur.x,cur.y + 1));
      consumablePointsCopy.add(consumablePoints.get(consumablePoints.size() - 1));
      if (debug)       g.drawLine(cur.x,cur.y + 1,cur.x,cur.y + 1);
      i=0;
      continue;
    }
    if (isConsumable(cur.x - 1,cur.y,consumablePointsCopy)) {
      consumablePoints.add(new Point(cur.x - 1,cur.y));
      consumablePointsCopy.add(consumablePoints.get(consumablePoints.size() - 1));
      if (debug)       g.drawLine(cur.x - 1,cur.y,cur.x - 1,cur.y);
      i=0;
      continue;
    }
    ++i;
  }
  while (consumablePoints.size() != amountOfArea)   consumablePoints.remove(amountOfArea);
  mPoints.removeAll(consumablePoints);
  log.exiting(className,"String_Node_Str");
  return consumablePoints;
}

Fixed version (ground truth):
/** 
 * Allows someone to consume pixels from this polygon. There are some edge cases where the requested number of points my not have actually been consumed if the expansion outward from the selected start point encounter problems. I'm trying to remove this annoyance, but for now that means that this method should be called in a loop, checking if the desired area was received.
 * @param amountOfArea the number of pixels desired. If this is greater than the size of this polygon, all polygon pixels are returned and this poly will deregister itself from the area
 * @param startPoint The point at which the merge will start. If the caller is positive that they will consume this entire polygon, then this can be null
 * @return all of the points that can be consumed, up toMath.min(amountOfArea,size). The caller should check the size to see if it got what it requested
 */
public Collection<Point> consumeArea(int amountOfArea,Point startPoint){
  log.entering(className,"String_Node_Str",new Object[]{amountOfArea,startPoint});
  if (amountOfArea >= getArea()) {
    mRegionManager.removeRegion(this);
    log.exiting(className,"String_Node_Str","String_Node_Str");
    return mPoints;
  }
  List<Point> consumablePoints=new ArrayList<Point>(amountOfArea + 8);
  Set<Point> consumablePointsCopy=new HashSet<Point>(amountOfArea + 8);
  if (isConsumable(startPoint.x,startPoint.y,null)) {
    log.finest("String_Node_Str");
    consumablePoints.add(startPoint);
    consumablePointsCopy.add(startPoint);
  }
 else {
    log.info("String_Node_Str");
    log.exiting(className,"String_Node_Str");
    return consumablePoints;
  }
  BufferedImage image=mRegionManager.getDebugImage(this);
  Graphics g=image.getGraphics();
  Point lastCur=null;
  int imageID=0;
  boolean debug=false;
  int i=0;
  int lastIterationListSize=0;
  Point cur=null;
  while (consumablePoints.size() < amountOfArea) {
    try {
      cur=consumablePoints.get(i);
    }
 catch (    IndexOutOfBoundsException ide) {
      if (lastIterationListSize == consumablePoints.size()) {
        mPoints.removeAll(consumablePoints);
        assert(isContigious());
        return consumablePoints;
      }
      log.finest("String_Node_Str");
      i=0;
      cur=consumablePoints.get(i);
      lastIterationListSize=consumablePoints.size();
    }
    if (cur == lastCur) {
    }
 else {
      StringBuilder name=new StringBuilder("String_Node_Str");
      if (imageID < 10)       name.append("String_Node_Str").append(imageID).append("String_Node_Str");
 else       if (imageID > 9 && imageID < 100)       name.append("String_Node_Str").append(imageID).append("String_Node_Str");
 else       if (imageID > 99 && imageID < 1000)       name.append("String_Node_Str").append(imageID).append("String_Node_Str");
 else       name.append(imageID).append("String_Node_Str");
      try {
        File f=new File(name.toString());
        ImageIO.write(image,"String_Node_Str",f);
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
      image=mRegionManager.getDebugImage(this);
      g=image.getGraphics();
      g.setColor(Color.GREEN);
      for (      Point p : consumablePoints)       g.drawLine(p.x,p.y,p.x,p.y);
      g.setColor(Color.RED);
      g.drawLine(cur.x,cur.y,cur.x,cur.y);
      lastCur=cur;
      imageID++;
    }
    g.setColor(Color.YELLOW);
    log.finest("String_Node_Str" + cur + "String_Node_Str");
    if (isConsumable(cur.x,cur.y - 1,consumablePointsCopy)) {
      consumablePoints.add(new Point(cur.x,cur.y - 1));
      consumablePointsCopy.add(consumablePoints.get(consumablePoints.size() - 1));
      if (debug)       g.drawLine(cur.x,cur.y - 1,cur.x,cur.y - 1);
      i=0;
      continue;
    }
    if (isConsumable(cur.x + 1,cur.y,consumablePointsCopy)) {
      consumablePoints.add(new Point(cur.x + 1,cur.y));
      consumablePointsCopy.add(consumablePoints.get(consumablePoints.size() - 1));
      if (debug)       g.drawLine(cur.x + 1,cur.y,cur.x + 1,cur.y);
      i=0;
      continue;
    }
    if (isConsumable(cur.x,cur.y + 1,consumablePointsCopy)) {
      consumablePoints.add(new Point(cur.x,cur.y + 1));
      consumablePointsCopy.add(consumablePoints.get(consumablePoints.size() - 1));
      if (debug)       g.drawLine(cur.x,cur.y + 1,cur.x,cur.y + 1);
      i=0;
      continue;
    }
    if (isConsumable(cur.x - 1,cur.y,consumablePointsCopy)) {
      consumablePoints.add(new Point(cur.x - 1,cur.y));
      consumablePointsCopy.add(consumablePoints.get(consumablePoints.size() - 1));
      if (debug)       g.drawLine(cur.x - 1,cur.y,cur.x - 1,cur.y);
      i=0;
      continue;
    }
    ++i;
  }
  while (consumablePoints.size() != amountOfArea)   consumablePoints.remove(amountOfArea);
  mPoints.removeAll(consumablePoints);
  log.exiting(className,"String_Node_Str");
  return consumablePoints;
}