Program: 25543
Project: 25543
Buggy source:
public void writeCoordinatesWithTileIds(final StackId stackId,final Double z,final List<TileCoordinates> worldCoordinatesList,final OutputStream outputStream) throws IllegalArgumentException, IOException {
  LOG.debug("String_Node_Str",stackId,z,worldCoordinatesList.size());
  MongoUtil.validateRequiredParameter("String_Node_Str",stackId);
  final MongoCollection<Document> tileCollection=getTileCollection(stackId);
  final Document tileKeys=new Document("String_Node_Str",1).append("String_Node_Str",0);
  final Document orderBy=new Document("String_Node_Str",1);
  final ProcessTimer timer=new ProcessTimer();
  final byte[] openBracket="String_Node_Str".getBytes();
  final byte[] comma="String_Node_Str".getBytes();
  final byte[] closeBracket="String_Node_Str".getBytes();
  int coordinateCount=0;
  double[] world;
  double coordinateZ=z == null ? 0 : z;
  Document tileQuery=new Document();
  MongoCursor<Document> cursor=null;
  Document document;
  Object tileId;
  String coordinatesJson;
  try {
    outputStream.write(openBracket);
    TileCoordinates worldCoordinates;
    for (int i=0; i < worldCoordinatesList.size(); i++) {
      worldCoordinates=worldCoordinatesList.get(i);
      world=worldCoordinates.getWorld();
      if (world == null) {
        throw new IllegalArgumentException("String_Node_Str" + i);
      }
 else       if (z == null) {
        if (world.length < 2) {
          throw new IllegalArgumentException("String_Node_Str" + i);
        }
      }
 else {
        if (world.length < 3) {
          throw new IllegalArgumentException("String_Node_Str" + i);
        }
        coordinateZ=world[2];
      }
      tileQuery=getIntersectsBoxQuery(coordinateZ,world[0],world[1],world[0],world[1]);
      cursor=tileCollection.find(tileQuery).projection(tileKeys).sort(orderBy).iterator();
      if (i > 0) {
        outputStream.write(comma);
      }
      outputStream.write(openBracket);
      if (cursor.hasNext()) {
        document=cursor.next();
        tileId=document.get("String_Node_Str");
        if (tileId != null) {
          worldCoordinates.setTileId(tileId.toString());
        }
        coordinatesJson=worldCoordinates.toJson();
        outputStream.write(coordinatesJson.getBytes());
        while (cursor.hasNext()) {
          document=cursor.next();
          tileId=document.get("String_Node_Str");
          if (tileId != null) {
            worldCoordinates.setTileId(tileId.toString());
          }
          coordinatesJson=worldCoordinates.toJson();
          outputStream.write(comma);
          outputStream.write(coordinatesJson.getBytes());
        }
      }
 else {
        coordinatesJson=worldCoordinates.toJson();
        outputStream.write(coordinatesJson.getBytes());
      }
      cursor.close();
      outputStream.write(closeBracket);
      coordinateCount++;
      if (timer.hasIntervalPassed()) {
        LOG.debug("String_Node_Str",coordinateCount);
      }
    }
    outputStream.write(closeBracket);
  }
  finally {
    if (cursor != null) {
      cursor.close();
    }
  }
  LOG.debug("String_Node_Str",coordinateCount,MongoUtil.fullName(tileCollection),tileQuery.toJson(),tileKeys.toJson(),orderBy.toJson(),timer.getElapsedSeconds());
}

Fixed version (ground truth):
public void writeCoordinatesWithTileIds(final StackId stackId,final Double z,final List<TileCoordinates> worldCoordinatesList,final OutputStream outputStream) throws IllegalArgumentException, IOException {
  LOG.debug("String_Node_Str",stackId,z,worldCoordinatesList.size());
  MongoUtil.validateRequiredParameter("String_Node_Str",stackId);
  final MongoCollection<Document> tileCollection=getTileCollection(stackId);
  final Document tileKeys=new Document("String_Node_Str",1).append("String_Node_Str",0);
  final Document orderBy=new Document("String_Node_Str",1);
  final ProcessTimer timer=new ProcessTimer();
  final byte[] openBracket="String_Node_Str".getBytes();
  final byte[] comma="String_Node_Str".getBytes();
  final byte[] closeBracket="String_Node_Str".getBytes();
  int coordinateCount=0;
  double[] world;
  double coordinateZ=z == null ? -1 : z;
  Document tileQuery=new Document();
  MongoCursor<Document> cursor=null;
  Document document;
  Object tileId;
  String coordinatesJson;
  try {
    outputStream.write(openBracket);
    TileCoordinates worldCoordinates;
    for (int i=0; i < worldCoordinatesList.size(); i++) {
      worldCoordinates=worldCoordinatesList.get(i);
      world=worldCoordinates.getWorld();
      if (world == null) {
        throw new IllegalArgumentException("String_Node_Str" + i);
      }
 else       if (z == null) {
        if (world.length < 3) {
          throw new IllegalArgumentException("String_Node_Str" + i);
        }
        coordinateZ=world[2];
      }
 else {
        if (world.length < 2) {
          throw new IllegalArgumentException("String_Node_Str" + i);
        }
      }
      tileQuery=getIntersectsBoxQuery(coordinateZ,world[0],world[1],world[0],world[1]);
      cursor=tileCollection.find(tileQuery).projection(tileKeys).sort(orderBy).iterator();
      if (i > 0) {
        outputStream.write(comma);
      }
      outputStream.write(openBracket);
      if (cursor.hasNext()) {
        document=cursor.next();
        tileId=document.get("String_Node_Str");
        if (tileId != null) {
          worldCoordinates.setTileId(tileId.toString());
        }
        coordinatesJson=worldCoordinates.toJson();
        outputStream.write(coordinatesJson.getBytes());
        while (cursor.hasNext()) {
          document=cursor.next();
          tileId=document.get("String_Node_Str");
          if (tileId != null) {
            worldCoordinates.setTileId(tileId.toString());
          }
          coordinatesJson=worldCoordinates.toJson();
          outputStream.write(comma);
          outputStream.write(coordinatesJson.getBytes());
        }
      }
 else {
        coordinatesJson=worldCoordinates.toJson();
        outputStream.write(coordinatesJson.getBytes());
      }
      cursor.close();
      outputStream.write(closeBracket);
      coordinateCount++;
      if (timer.hasIntervalPassed()) {
        LOG.debug("String_Node_Str",coordinateCount);
      }
    }
    outputStream.write(closeBracket);
  }
  finally {
    if (cursor != null) {
      cursor.close();
    }
  }
  LOG.debug("String_Node_Str",coordinateCount,MongoUtil.fullName(tileCollection),tileQuery.toJson(),tileKeys.toJson(),orderBy.toJson(),timer.getElapsedSeconds());
}