Program: 3231
Project: 3231
Buggy source:
/** 
 * Recursively replace one or more DSpace Objects out of the contents of the ingested package (and all other referenced packages). The initial object to replace is indicated by <code>dso</code>.  All other objects are replaced based on information provided in the referenced packages. <p> For example, a scenario may be to replace a Collection based on a collection-level package, and also replace *every* Item in that collection based on the item-level packages referenced by the collection-level package. <p> Please note that since the <code>dso</code> input only specifies the initial object to replace, any additional objects to replace must be determined based on the referenced packages (or initial package itself). <p> The output of this method is one or more replaced <code>DspaceObject<code>s. <p> The packager <em>may</em> choose not to implement <code>replaceAll</code>, since it somewhat contradicts the archival nature of DSpace. It also may choose to forward the call to <code>replace</code> if it is unable to support recursive replacement.
 * @param context  DSpace context.
 * @param dso initial existing DSpace Object to be replaced, may be nullif object to replace can be determined from package
 * @param pkgFile  The package file to ingest.
 * @param params Properties-style list of options specific to this packager
 * @return List of DSpaceObjects replaced
 * @throws PackageValidationException if initial package (or any referenced package)is unacceptable or there is a fatal error in creating a DSpaceObject
 * @throws UnsupportedOperationException if this packager does notimplement <code>replaceAll</code>
 */
public List<DSpaceObject> replaceAll(Context context,DSpaceObject dso,File pkgFile,PackageParameters params) throws PackageException, UnsupportedOperationException, CrosswalkException, AuthorizeException, SQLException, IOException {
  if (!params.recursiveModeEnabled()) {
    params.setRecursiveModeEnabled(true);
  }
  DSpaceObject replacedDso=replace(context,dso,pkgFile,params);
  log.info(LogManager.getHeader(context,"String_Node_Str","String_Node_Str" + Constants.typeText[replacedDso.getType()] + "String_Node_Str"+ replacedDso.getHandle()));
  addToIngestedList(replacedDso);
  if (replacedDso.getType() != Constants.ITEM) {
    List<String> childPkgRefs=getPackageReferences(replacedDso);
    if (childPkgRefs != null && !childPkgRefs.isEmpty()) {
      for (      String childPkgRef : childPkgRefs) {
        int oldSize=dsoIngestedList.size();
        File childPkg=new File(pkgFile.getAbsoluteFile().getParent(),childPkgRef);
        replaceAll(context,null,childPkg,params);
        if (Constants.COLLECTION == replacedDso.getType()) {
          Item childItem=(Item)dsoIngestedList.get(oldSize);
          Collection collection=(Collection)replacedDso;
          if (!childItem.isIn(collection)) {
            collection.addItem(childItem);
          }
        }
      }
    }
  }
  return getIngestedList();
}

Fixed version (ground truth):
/** 
 * Recursively replace one or more DSpace Objects out of the contents of the ingested package (and all other referenced packages). The initial object to replace is indicated by <code>dso</code>.  All other objects are replaced based on information provided in the referenced packages. <p> For example, a scenario may be to replace a Collection based on a collection-level package, and also replace *every* Item in that collection based on the item-level packages referenced by the collection-level package. <p> Please note that since the <code>dso</code> input only specifies the initial object to replace, any additional objects to replace must be determined based on the referenced packages (or initial package itself). <p> The output of this method is one or more replaced <code>DspaceObject<code>s. <p> The packager <em>may</em> choose not to implement <code>replaceAll</code>, since it somewhat contradicts the archival nature of DSpace. It also may choose to forward the call to <code>replace</code> if it is unable to support recursive replacement.
 * @param context  DSpace context.
 * @param dso initial existing DSpace Object to be replaced, may be nullif object to replace can be determined from package
 * @param pkgFile  The package file to ingest.
 * @param params Properties-style list of options specific to this packager
 * @return List of DSpaceObjects replaced
 * @throws PackageValidationException if initial package (or any referenced package)is unacceptable or there is a fatal error in creating a DSpaceObject
 * @throws UnsupportedOperationException if this packager does notimplement <code>replaceAll</code>
 */
@Override public List<DSpaceObject> replaceAll(Context context,DSpaceObject dso,File pkgFile,PackageParameters params) throws PackageException, UnsupportedOperationException, CrosswalkException, AuthorizeException, SQLException, IOException {
  if (!params.recursiveModeEnabled()) {
    params.setRecursiveModeEnabled(true);
  }
  DSpaceObject replacedDso=replace(context,dso,pkgFile,params);
  log.info(LogManager.getHeader(context,"String_Node_Str","String_Node_Str" + Constants.typeText[replacedDso.getType()] + "String_Node_Str"+ replacedDso.getHandle()));
  addToIngestedList(replacedDso);
  if (replacedDso.getType() != Constants.ITEM) {
    List<String> childPkgRefs=getPackageReferences(replacedDso);
    if (childPkgRefs != null && !childPkgRefs.isEmpty()) {
      for (      String childPkgRef : childPkgRefs) {
        int oldSize=dsoIngestedList.size();
        File childPkg=new File(pkgFile.getAbsoluteFile().getParent(),childPkgRef);
        replaceAll(context,null,childPkg,params);
        if (Constants.COLLECTION == replacedDso.getType()) {
          Item childItem=(Item)dsoIngestedList.get(oldSize);
          Collection collection=(Collection)replacedDso;
          if (!childItem.isIn(collection)) {
            collection.addItem(childItem);
          }
        }
      }
    }
  }
  return getIngestedList();
}