Program: 52262
Project: 52262
Buggy source:
/** 
 * Does the work creating a List with all the Items in the Community or Collection It then kicks off a new Thread to export the items, zip the export directory and send confirmation email
 * @param dsObjects - List of dspace objects to process
 * @param context - the dspace context
 * @param additionalEmail - email address to cc in addition the the current user email
 * @throws Exception
 */
private static void processDownloadableExport(List<DSpaceObject> dsObjects,Context context,final String additionalEmail) throws Exception {
  final EPerson eperson=context.getCurrentUser();
  deleteOldExportArchives(eperson.getID());
  float size=0;
  final ArrayList<Integer> items=new ArrayList<Integer>();
  for (  DSpaceObject dso : dsObjects) {
    if (dso.getType() == Constants.COMMUNITY) {
      Community community=(Community)dso;
      Collection[] collections=community.getCollections();
      for (      Collection collection : collections) {
        ItemIterator iitems=collection.getItems();
        try {
          while (iitems.hasNext()) {
            Item item=iitems.next();
            Bundle[] bundles=item.getBundles();
            for (            Bundle bundle : bundles) {
              Bitstream[] bitstreams=bundle.getBitstreams();
              for (              Bitstream bit : bitstreams) {
                size+=bit.getSize();
              }
            }
            items.add(item.getID());
          }
        }
  finally {
          if (iitems != null)           iitems.close();
        }
      }
    }
 else     if (dso.getType() == Constants.COLLECTION) {
      Collection collection=(Collection)dso;
      ItemIterator iitems=collection.getItems();
      try {
        while (iitems.hasNext()) {
          Item item=iitems.next();
          Bundle[] bundles=item.getBundles();
          for (          Bundle bundle : bundles) {
            Bitstream[] bitstreams=bundle.getBitstreams();
            for (            Bitstream bit : bitstreams) {
              size+=bit.getSize();
            }
          }
          items.add(item.getID());
        }
      }
  finally {
        if (iitems != null)         iitems.close();
      }
    }
 else     if (dso.getType() == Constants.ITEM) {
      Item item=(Item)dso;
      Bundle[] bundles=item.getBundles();
      for (      Bundle bundle : bundles) {
        Bitstream[] bitstreams=bundle.getBitstreams();
        for (        Bitstream bit : bitstreams) {
          size+=bit.getSize();
        }
      }
      items.add(item.getID());
    }
 else {
    }
  }
  String megaBytes=ConfigurationManager.getProperty("String_Node_Str");
  if (megaBytes != null) {
    float maxSize=0;
    try {
      maxSize=Float.parseFloat(megaBytes);
    }
 catch (    Exception e) {
    }
    if (maxSize > 0) {
      if (maxSize < (size / 1048576.00)) {
        throw new Exception("String_Node_Str");
      }
    }
  }
  if (items.size() > 0) {
    Thread go=new Thread(){
      public void run(){
        Context context;
        ItemIterator iitems=null;
        try {
          context=new Context();
          context.setIgnoreAuthorization(true);
          iitems=new ItemIterator(context,items);
          String fileName=assembleFileName("String_Node_Str",eperson,new Date());
          String workDir=getExportWorkDirectory() + System.getProperty("String_Node_Str") + fileName;
          String downloadDir=getExportDownloadDirectory(eperson.getID());
          File wkDir=new File(workDir);
          if (!wkDir.exists()) {
            wkDir.mkdirs();
          }
          File dnDir=new File(downloadDir);
          if (!dnDir.exists()) {
            dnDir.mkdirs();
          }
          exportItem(context,iitems,workDir,1);
          zip(workDir,downloadDir + System.getProperty("String_Node_Str") + fileName+ "String_Node_Str");
          emailSuccessMessage(context,eperson,fileName + "String_Node_Str");
          context.setIgnoreAuthorization(false);
        }
 catch (        Exception e1) {
          try {
            emailErrorMessage(eperson,e1.getMessage());
          }
 catch (          Exception e) {
          }
          throw new RuntimeException(e1);
        }
 finally {
          if (iitems != null)           iitems.close();
        }
      }
    }
;
    go.isDaemon();
    go.start();
  }
}

Fixed version (ground truth):
/** 
 * Does the work creating a List with all the Items in the Community or Collection It then kicks off a new Thread to export the items, zip the export directory and send confirmation email
 * @param dsObjects - List of dspace objects to process
 * @param context - the dspace context
 * @param additionalEmail - email address to cc in addition the the current user email
 * @throws Exception
 */
private static void processDownloadableExport(List<DSpaceObject> dsObjects,Context context,final String additionalEmail) throws Exception {
  final EPerson eperson=context.getCurrentUser();
  deleteOldExportArchives(eperson.getID());
  float size=0;
  final ArrayList<Integer> items=new ArrayList<Integer>();
  for (  DSpaceObject dso : dsObjects) {
    if (dso.getType() == Constants.COMMUNITY) {
      Community community=(Community)dso;
      Collection[] collections=community.getCollections();
      for (      Collection collection : collections) {
        ItemIterator iitems=collection.getItems();
        try {
          while (iitems.hasNext()) {
            Item item=iitems.next();
            Bundle[] bundles=item.getBundles();
            for (            Bundle bundle : bundles) {
              Bitstream[] bitstreams=bundle.getBitstreams();
              for (              Bitstream bit : bitstreams) {
                size+=bit.getSize();
              }
            }
            items.add(item.getID());
          }
        }
  finally {
          if (iitems != null)           iitems.close();
        }
      }
    }
 else     if (dso.getType() == Constants.COLLECTION) {
      Collection collection=(Collection)dso;
      ItemIterator iitems=collection.getItems();
      try {
        while (iitems.hasNext()) {
          Item item=iitems.next();
          Bundle[] bundles=item.getBundles();
          for (          Bundle bundle : bundles) {
            Bitstream[] bitstreams=bundle.getBitstreams();
            for (            Bitstream bit : bitstreams) {
              size+=bit.getSize();
            }
          }
          items.add(item.getID());
        }
      }
  finally {
        if (iitems != null)         iitems.close();
      }
    }
 else     if (dso.getType() == Constants.ITEM) {
      Item item=(Item)dso;
      Bundle[] bundles=item.getBundles();
      for (      Bundle bundle : bundles) {
        Bitstream[] bitstreams=bundle.getBitstreams();
        for (        Bitstream bit : bitstreams) {
          size+=bit.getSize();
        }
      }
      items.add(item.getID());
    }
 else {
    }
  }
  String megaBytes=ConfigurationManager.getProperty("String_Node_Str");
  if (megaBytes != null) {
    float maxSize=0;
    try {
      maxSize=Float.parseFloat(megaBytes);
    }
 catch (    Exception e) {
    }
    if (maxSize > 0) {
      if (maxSize < (size / 1048576.00)) {
        throw new Exception("String_Node_Str");
      }
    }
  }
  if (items.size() > 0) {
    Thread go=new Thread(){
      public void run(){
        Context context=null;
        ItemIterator iitems=null;
        try {
          context=new Context();
          context.setIgnoreAuthorization(true);
          iitems=new ItemIterator(context,items);
          String fileName=assembleFileName("String_Node_Str",eperson,new Date());
          String workDir=getExportWorkDirectory() + System.getProperty("String_Node_Str") + fileName;
          String downloadDir=getExportDownloadDirectory(eperson.getID());
          File wkDir=new File(workDir);
          if (!wkDir.exists()) {
            wkDir.mkdirs();
          }
          File dnDir=new File(downloadDir);
          if (!dnDir.exists()) {
            dnDir.mkdirs();
          }
          exportItem(context,iitems,workDir,1);
          zip(workDir,downloadDir + System.getProperty("String_Node_Str") + fileName+ "String_Node_Str");
          emailSuccessMessage(context,eperson,fileName + "String_Node_Str");
          context.setIgnoreAuthorization(false);
        }
 catch (        Exception e1) {
          try {
            emailErrorMessage(eperson,e1.getMessage());
          }
 catch (          Exception e) {
          }
          throw new RuntimeException(e1);
        }
 finally {
          if (iitems != null)           iitems.close();
          try {
            context.complete();
          }
 catch (          SQLException sqle) {
            context.abort();
          }
        }
      }
    }
;
    go.isDaemon();
    go.start();
  }
}