Program: 3331
Project: 3331
Buggy source:
/** 
 * Obtain information about items that have been created, modified or withdrawn within a given date range. You can also specify 'offset' and 'limit' so that a big harvest can be split up into smaller sections. <P> Note that dates are passed in the standard ISO8601 format used by DSpace (and OAI-PMH). <P> FIXME: Assumes all in_archive items have public metadata
 * @param context DSpace context
 * @param scope a Collection, Community, or <code>null</code> indicating the scope is all of DSpace
 * @param startDate start of date range, or <code>null</code>
 * @param endDate end of date range, or <code>null</code>
 * @param offset for a partial harvest, the point in the overall list of matching items to start at. 0 means just start at the beginning.
 * @param limit the number of matching items to return in a partial harvest. Specify 0 to return the whole list (or the rest of the list if an offset was specified.)
 * @param items if <code>true</code> the <code>item</code> field of each <code>HarvestedItemInfo</code> object is filled out
 * @param collections if <code>true</code> the <code>collectionHandles</code> field of each <code>HarvestedItemInfo</code> object is filled out
 * @param withdrawn If <code>true</code>, information about withdrawn items is included
 * @return List of <code>HarvestedItemInfo</code> objects
 * @throws SQLException
 * @throws ParseException If the date is not in a supported format
 */
public static List harvest(Context context,DSpaceObject scope,String startDate,String endDate,int offset,int limit,boolean items,boolean collections,boolean withdrawn) throws SQLException, ParseException {
  String query="String_Node_Str";
  List parameters=new ArrayList();
  if (scope != null) {
    if (scope.getType() == Constants.COLLECTION) {
      query+="String_Node_Str";
    }
 else     if (scope.getType() == Constants.COMMUNITY) {
      query+="String_Node_Str";
    }
  }
  query+="String_Node_Str" + Constants.ITEM + "String_Node_Str";
  if (scope != null) {
    if (scope.getType() == Constants.COLLECTION) {
      query+="String_Node_Str" + "String_Node_Str";
      parameters.add(new Integer(scope.getID()));
    }
 else     if (scope.getType() == Constants.COMMUNITY) {
      query+="String_Node_Str" + "String_Node_Str";
      parameters.add(new Integer(scope.getID()));
    }
  }
  if (startDate != null) {
    query=query + "String_Node_Str";
    parameters.add(toTimestamp(startDate,false));
  }
  if (endDate != null) {
    boolean selfGenerated=false;
    if (endDate.length() == 20) {
      endDate=endDate.substring(0,19) + "String_Node_Str";
      selfGenerated=true;
    }
    query+="String_Node_Str";
    parameters.add(toTimestamp(endDate,selfGenerated));
  }
  if (withdrawn == false) {
    if ("String_Node_Str".equals(ConfigurationManager.getProperty("String_Node_Str"))) {
      query+="String_Node_Str";
    }
 else {
      query+="String_Node_Str";
    }
  }
  query+="String_Node_Str";
  log.debug(LogManager.getHeader(context,"String_Node_Str",query));
  Object[] parametersArray=parameters.toArray();
  TableRowIterator tri=DatabaseManager.query(context,query,parametersArray);
  List infoObjects=new LinkedList();
  int index=0;
  try {
    while (tri.hasNext()) {
      TableRow row=tri.next();
      if ((index >= offset) && ((limit == 0) || (index < (offset + limit)))) {
        HarvestedItemInfo itemInfo=new HarvestedItemInfo();
        itemInfo.context=context;
        itemInfo.handle=row.getStringColumn("String_Node_Str");
        itemInfo.itemID=row.getIntColumn("String_Node_Str");
        itemInfo.datestamp=row.getDateColumn("String_Node_Str");
        itemInfo.withdrawn=row.getBooleanColumn("String_Node_Str");
        if (collections) {
          fillCollections(context,itemInfo);
        }
        if (items) {
          itemInfo.item=Item.find(context,itemInfo.itemID);
        }
        infoObjects.add(itemInfo);
      }
      index++;
    }
  }
  finally {
    if (tri != null)     tri.close();
  }
  return infoObjects;
}

Fixed version (ground truth):
/** 
 * Obtain information about items that have been created, modified or withdrawn within a given date range. You can also specify 'offset' and 'limit' so that a big harvest can be split up into smaller sections. <P> Note that dates are passed in the standard ISO8601 format used by DSpace (and OAI-PMH). <P> FIXME: Assumes all in_archive items have public metadata
 * @param context DSpace context
 * @param scope a Collection, Community, or <code>null</code> indicating the scope is all of DSpace
 * @param startDate start of date range, or <code>null</code>
 * @param endDate end of date range, or <code>null</code>
 * @param offset for a partial harvest, the point in the overall list of matching items to start at. 0 means just start at the beginning.
 * @param limit the number of matching items to return in a partial harvest. Specify 0 to return the whole list (or the rest of the list if an offset was specified.)
 * @param items if <code>true</code> the <code>item</code> field of each <code>HarvestedItemInfo</code> object is filled out
 * @param collections if <code>true</code> the <code>collectionHandles</code> field of each <code>HarvestedItemInfo</code> object is filled out
 * @param withdrawn If <code>true</code>, information about withdrawn items is included
 * @param nonAnon If items without anonymous access should be included or not
 * @return List of <code>HarvestedItemInfo</code> objects
 * @throws SQLException
 * @throws ParseException If the date is not in a supported format
 */
public static List harvest(Context context,DSpaceObject scope,String startDate,String endDate,int offset,int limit,boolean items,boolean collections,boolean withdrawn,boolean nonAnon) throws SQLException, ParseException {
  String query="String_Node_Str";
  List parameters=new ArrayList();
  if (scope != null) {
    if (scope.getType() == Constants.COLLECTION) {
      query+="String_Node_Str";
    }
 else     if (scope.getType() == Constants.COMMUNITY) {
      query+="String_Node_Str";
    }
  }
  query+="String_Node_Str" + Constants.ITEM + "String_Node_Str";
  if (scope != null) {
    if (scope.getType() == Constants.COLLECTION) {
      query+="String_Node_Str" + "String_Node_Str";
      parameters.add(new Integer(scope.getID()));
    }
 else     if (scope.getType() == Constants.COMMUNITY) {
      query+="String_Node_Str" + "String_Node_Str";
      parameters.add(new Integer(scope.getID()));
    }
  }
  if (startDate != null) {
    query=query + "String_Node_Str";
    parameters.add(toTimestamp(startDate,false));
  }
  if (endDate != null) {
    boolean selfGenerated=false;
    if (endDate.length() == 20) {
      endDate=endDate.substring(0,19) + "String_Node_Str";
      selfGenerated=true;
    }
    query+="String_Node_Str";
    parameters.add(toTimestamp(endDate,selfGenerated));
  }
  if (withdrawn == false) {
    if ("String_Node_Str".equals(ConfigurationManager.getProperty("String_Node_Str"))) {
      query+="String_Node_Str";
    }
 else {
      query+="String_Node_Str";
    }
  }
  query+="String_Node_Str";
  log.debug(LogManager.getHeader(context,"String_Node_Str",query));
  Object[] parametersArray=parameters.toArray();
  TableRowIterator tri=DatabaseManager.query(context,query,parametersArray);
  List infoObjects=new LinkedList();
  int index=0;
  try {
    while (tri.hasNext()) {
      TableRow row=tri.next();
      if ((index >= offset) && ((limit == 0) || (index < (offset + limit)))) {
        HarvestedItemInfo itemInfo=new HarvestedItemInfo();
        itemInfo.context=context;
        itemInfo.handle=row.getStringColumn("String_Node_Str");
        itemInfo.itemID=row.getIntColumn("String_Node_Str");
        itemInfo.datestamp=row.getDateColumn("String_Node_Str");
        itemInfo.withdrawn=row.getBooleanColumn("String_Node_Str");
        if (collections) {
          fillCollections(context,itemInfo);
        }
        if (items) {
          itemInfo.item=Item.find(context,itemInfo.itemID);
        }
        if (nonAnon) {
          infoObjects.add(itemInfo);
        }
 else {
          Group[] authorizedGroups=AuthorizeManager.getAuthorizedGroups(context,itemInfo.item,Constants.READ);
          boolean added=false;
          for (int i=0; i < authorizedGroups.length; i++) {
            if ((authorizedGroups[i].getID() == 0) && (!added)) {
              infoObjects.add(itemInfo);
              added=true;
            }
          }
        }
      }
      index++;
    }
  }
  finally {
    if (tri != null)     tri.close();
  }
  return infoObjects;
}