Program: 3232
Project: 3232
Buggy source:
/** 
 * Recursively export one or more DSpace Objects as a series of packages. This method will export the given DSpace Object as well as all referenced DSpaceObjects (e.g. child objects) into a series of packages. The initial object is exported to the location specified by the OutputStream. All other packages are exported to the same directory location. <p> Package is any serialized representation of the item, at the discretion of the implementing class.  It does not have to include content bitstreams. <br> Use the <code>params</code> parameter list to adjust the way the package is made, e.g. including a "<code>metadataOnly</code>" parameter might make the package a bare manifest in XML instead of a Zip file including manifest and contents. <br> Throws an exception of the initial object is not acceptable or there is a failure creating the package.
 * @param context  DSpace context.
 * @param dso  initial DSpace object
 * @param params Properties-style list of options specific to this packager
 * @param pkgFile File where initial package should be written. All otherpackages will be written to the same directory as this File.
 * @throws PackageValidationException if package cannot be created or there isa fatal error in creating it.
 */
public List<File> disseminateAll(Context context,DSpaceObject dso,PackageParameters params,File pkgFile) throws PackageException, CrosswalkException, AuthorizeException, SQLException, IOException {
  if (!params.recursiveModeEnabled()) {
    params.setRecursiveModeEnabled(true);
  }
  disseminate(context,dso,params,pkgFile);
  if (pkgFile.exists()) {
    addToPackageList(pkgFile);
    if (dso.getType() != Constants.ITEM) {
      String pkgDirectory=pkgFile.getCanonicalFile().getParent();
      if (!pkgDirectory.endsWith(File.separator)) {
        pkgDirectory+=File.separator;
      }
      String fileExtension=PackageUtils.getFileExtension(pkgFile.getName());
switch (dso.getType()) {
case Constants.COLLECTION:
        Collection collection=(Collection)dso;
      ItemIterator iterator=collection.getItems();
    while (iterator.hasNext()) {
      Item item=iterator.next();
      String childFileName=pkgDirectory + PackageUtils.getPackageName(item,fileExtension);
      disseminateAll(context,item,params,new File(childFileName));
    }
  break;
case Constants.COMMUNITY:
Community community=(Community)dso;
Community[] subcommunities=community.getSubcommunities();
for (int i=0; i < subcommunities.length; i++) {
String childFileName=pkgDirectory + PackageUtils.getPackageName(subcommunities[i],fileExtension);
disseminateAll(context,subcommunities[i],params,new File(childFileName));
}
Collection[] collections=community.getCollections();
for (int i=0; i < collections.length; i++) {
String childFileName=pkgDirectory + PackageUtils.getPackageName(collections[i],fileExtension);
disseminateAll(context,collections[i],params,new File(childFileName));
}
break;
case Constants.SITE:
Community[] topCommunities=Community.findAllTop(context);
for (int i=0; i < topCommunities.length; i++) {
String childFileName=pkgDirectory + PackageUtils.getPackageName(topCommunities[i],fileExtension);
disseminateAll(context,topCommunities[i],params,new File(childFileName));
}
break;
}
}
}
return getPackageList();
}

Fixed version (ground truth):
/** 
 * Recursively export one or more DSpace Objects as a series of packages. This method will export the given DSpace Object as well as all referenced DSpaceObjects (e.g. child objects) into a series of packages. The initial object is exported to the location specified by the OutputStream. All other packages are exported to the same directory location. <p> Package is any serialized representation of the item, at the discretion of the implementing class.  It does not have to include content bitstreams. <br> Use the <code>params</code> parameter list to adjust the way the package is made, e.g. including a "<code>metadataOnly</code>" parameter might make the package a bare manifest in XML instead of a Zip file including manifest and contents. <br> Throws an exception of the initial object is not acceptable or there is a failure creating the package.
 * @param context  DSpace context.
 * @param dso  initial DSpace object
 * @param params Properties-style list of options specific to this packager
 * @param pkgFile File where initial package should be written. All otherpackages will be written to the same directory as this File.
 * @throws PackageValidationException if package cannot be created or there isa fatal error in creating it.
 */
@Override public List<File> disseminateAll(Context context,DSpaceObject dso,PackageParameters params,File pkgFile) throws PackageException, CrosswalkException, AuthorizeException, SQLException, IOException {
  if (!params.recursiveModeEnabled()) {
    params.setRecursiveModeEnabled(true);
  }
  disseminate(context,dso,params,pkgFile);
  if (pkgFile.exists()) {
    addToPackageList(pkgFile);
    if (dso.getType() != Constants.ITEM) {
      String pkgDirectory=pkgFile.getCanonicalFile().getParent();
      if (!pkgDirectory.endsWith(File.separator)) {
        pkgDirectory+=File.separator;
      }
      String fileExtension=PackageUtils.getFileExtension(pkgFile.getName());
switch (dso.getType()) {
case Constants.COLLECTION:
        Collection collection=(Collection)dso;
      ItemIterator iterator=collection.getItems();
    while (iterator.hasNext()) {
      Item item=iterator.next();
      String childFileName=pkgDirectory + PackageUtils.getPackageName(item,fileExtension);
      disseminateAll(context,item,params,new File(childFileName));
    }
  break;
case Constants.COMMUNITY:
Community community=(Community)dso;
Community[] subcommunities=community.getSubcommunities();
for (int i=0; i < subcommunities.length; i++) {
String childFileName=pkgDirectory + PackageUtils.getPackageName(subcommunities[i],fileExtension);
disseminateAll(context,subcommunities[i],params,new File(childFileName));
}
Collection[] collections=community.getCollections();
for (int i=0; i < collections.length; i++) {
String childFileName=pkgDirectory + PackageUtils.getPackageName(collections[i],fileExtension);
disseminateAll(context,collections[i],params,new File(childFileName));
}
break;
case Constants.SITE:
Community[] topCommunities=Community.findAllTop(context);
for (int i=0; i < topCommunities.length; i++) {
String childFileName=pkgDirectory + PackageUtils.getPackageName(topCommunities[i],fileExtension);
disseminateAll(context,topCommunities[i],params,new File(childFileName));
}
break;
}
}
}
return getPackageList();
}