Program: 52025
Project: 52025
Buggy source:
/** 
 * Given a local file or public URL to a zip file that has the Simple Archive Format, this method imports the contents to DSpace
 * @param filepath The filepath to local file or the public URL of the zip file
 * @param owningCollection The owning collection the items will belong to
 * @param otherCollections The collections the created items will be inserted to, apart from the owning one
 * @param resumeDir In case of a resume request, the directory that containsthe old mapfile and data 
 * @param inputType The input type of the data (bibtex, csv, etc.), in case of local file
 * @param context The context
 * @throws Exception
 */
public static void processUIImport(String filepath,Collection owningCollection,String[] otherCollections,String resumeDir,String inputType,Context context) throws Exception {
  final EPerson oldEPerson=context.getCurrentUser();
  final String[] theOtherCollections=otherCollections;
  final Collection theOwningCollection=owningCollection;
  final String theFilePath=filepath;
  final String theInputType=inputType;
  final String theResumeDir=resumeDir;
  Thread go=new Thread(){
    public void run(){
      Context context=null;
      String importDir=null;
      EPerson eperson=null;
      try {
        context=new Context();
        eperson=EPerson.find(context,oldEPerson.getID());
        context.setCurrentUser(eperson);
        context.setIgnoreAuthorization(true);
        boolean isResume=theResumeDir != null;
        List<Collection> collectionList=new ArrayList<Collection>();
        if (theOtherCollections != null) {
          for (          String colID : theOtherCollections) {
            int colId=Integer.parseInt(colID);
            if (colId != theOwningCollection.getID()) {
              Collection col=Collection.find(context,colId);
              if (col != null) {
                collectionList.add(col);
              }
            }
          }
        }
        Collection[] otherCollections=collectionList.toArray(new Collection[collectionList.size()]);
        importDir=ConfigurationManager.getProperty("String_Node_Str") + File.separator + "String_Node_Str"+ File.separator+ context.getCurrentUser().getID()+ File.separator+ (isResume ? theResumeDir : (new GregorianCalendar()).getTimeInMillis());
        File importDirFile=new File(importDir);
        if (!importDirFile.exists()) {
          boolean success=importDirFile.mkdirs();
          if (!success) {
            log.info("String_Node_Str");
            throw new Exception("String_Node_Str");
          }
        }
        String dataPath=null;
        String dataDir=null;
        if (theInputType.equals("String_Node_Str")) {
          dataPath=importDirFile + File.separator + "String_Node_Str";
          dataDir=importDirFile + File.separator + "String_Node_Str"+ File.separator;
        }
 else         if (theInputType.equals("String_Node_Str")) {
          FileUtils.copyFileToDirectory(new File(theFilePath),importDirFile);
          dataPath=importDirFile + File.separator + (new File(theFilePath)).getName();
          dataDir=importDirFile + File.separator + "String_Node_Str"+ File.separator;
        }
 else {
          dataPath=importDirFile + File.separator + (new File(theFilePath)).getName();
          dataDir=importDirFile + File.separator + "String_Node_Str"+ File.separator;
        }
        if (isResume) {
          (new File(dataPath)).delete();
          FileDeleteStrategy.FORCE.delete(new File(dataDir));
        }
        String sourcePath=null;
        if (theInputType.equals("String_Node_Str")) {
          OutputStream os=new FileOutputStream(dataPath);
          byte[] b=new byte[2048];
          int length;
          InputStream is=new URL(theFilePath).openStream();
          while ((length=is.read(b)) != -1) {
            os.write(b,0,length);
          }
          is.close();
          os.close();
          sourcePath=unzip(new File(dataPath),dataDir);
          FileUtils.moveDirectory(new File(sourcePath),new File(importDirFile + File.separator + "String_Node_Str"+ File.separator));
          FileDeleteStrategy.FORCE.delete(new File(dataDir));
          dataDir=importDirFile + File.separator + "String_Node_Str"+ File.separator;
        }
 else         if (theInputType.equals("String_Node_Str")) {
          sourcePath=unzip(new File(dataPath),dataDir);
          FileUtils.moveDirectory(new File(sourcePath),new File(importDirFile + File.separator + "String_Node_Str"+ File.separator));
          FileDeleteStrategy.FORCE.delete(new File(dataDir));
          dataDir=importDirFile + File.separator + "String_Node_Str"+ File.separator;
        }
        String mapFilePath=importDirFile + File.separator + "String_Node_Str";
        Collection[] finalCollections=null;
        if (theOwningCollection != null) {
          finalCollections=new Collection[otherCollections.length + 1];
          finalCollections[0]=theOwningCollection;
          for (int i=0; i < otherCollections.length; i++) {
            finalCollections[i + 1]=otherCollections[i];
          }
        }
        ItemImport myloader=new ItemImport();
        myloader.isResume=isResume;
        if (theInputType.equals("String_Node_Str") || theInputType.equals("String_Node_Str")) {
          myloader.addItems(context,finalCollections,dataDir,mapFilePath,template);
        }
 else {
          myloader.addBTEItems(context,finalCollections,theFilePath,mapFilePath,template,theInputType,dataDir);
        }
        emailSuccessMessage(context,eperson,mapFilePath);
        context.complete();
      }
 catch (      Exception e) {
        e.printStackTrace();
        String exceptionString=ExceptionUtils.getStackTrace(e);
        if (mapOut != null) {
          mapOut.close();
        }
        mapOut=null;
        try {
          File importDirFile=new File(importDir + File.separator + "String_Node_Str");
          PrintWriter errorWriter=new PrintWriter(importDirFile);
          errorWriter.print(exceptionString);
          errorWriter.close();
          emailErrorMessage(eperson,exceptionString);
          throw new Exception(e.getMessage());
        }
 catch (        Exception e2) {
        }
      }
 finally {
        if (mapOut != null) {
          mapOut.close();
        }
        try {
          context.complete();
        }
 catch (        SQLException sqle) {
          context.abort();
        }
      }
    }
  }
;
  go.isDaemon();
  go.start();
}

Fixed version (ground truth):
/** 
 * Given a local file or public URL to a zip file that has the Simple Archive Format, this method imports the contents to DSpace
 * @param filepath The filepath to local file or the public URL of the zip file
 * @param owningCollection The owning collection the items will belong to
 * @param otherCollections The collections the created items will be inserted to, apart from the owning one
 * @param resumeDir In case of a resume request, the directory that containsthe old mapfile and data 
 * @param inputType The input type of the data (bibtex, csv, etc.), in case of local file
 * @param context The context
 * @throws Exception
 */
public static void processUIImport(String filepath,Collection owningCollection,String[] otherCollections,String resumeDir,String inputType,Context context) throws Exception {
  final EPerson oldEPerson=context.getCurrentUser();
  final String[] theOtherCollections=otherCollections;
  final Collection theOwningCollection=owningCollection;
  final String theFilePath=filepath;
  final String theInputType=inputType;
  final String theResumeDir=resumeDir;
  Thread go=new Thread(){
    public void run(){
      Context context=null;
      String importDir=null;
      EPerson eperson=null;
      try {
        context=new Context();
        eperson=EPerson.find(context,oldEPerson.getID());
        context.setCurrentUser(eperson);
        context.setIgnoreAuthorization(true);
        boolean isResume=theResumeDir != null;
        List<Collection> collectionList=new ArrayList<Collection>();
        if (theOtherCollections != null) {
          for (          String colID : theOtherCollections) {
            int colId=Integer.parseInt(colID);
            if (colId != theOwningCollection.getID()) {
              Collection col=Collection.find(context,colId);
              if (col != null) {
                collectionList.add(col);
              }
            }
          }
        }
        Collection[] otherCollections=collectionList.toArray(new Collection[collectionList.size()]);
        importDir=ConfigurationManager.getProperty("String_Node_Str") + File.separator + "String_Node_Str"+ File.separator+ context.getCurrentUser().getID()+ File.separator+ (isResume ? theResumeDir : (new GregorianCalendar()).getTimeInMillis());
        File importDirFile=new File(importDir);
        if (!importDirFile.exists()) {
          boolean success=importDirFile.mkdirs();
          if (!success) {
            log.info("String_Node_Str");
            throw new Exception("String_Node_Str");
          }
        }
        String dataPath=null;
        String dataDir=null;
        if (theInputType.equals("String_Node_Str")) {
          dataPath=importDirFile + File.separator + "String_Node_Str";
          dataDir=importDirFile + File.separator + "String_Node_Str"+ File.separator;
        }
 else         if (theInputType.equals("String_Node_Str")) {
          FileUtils.copyFileToDirectory(new File(theFilePath),importDirFile);
          dataPath=importDirFile + File.separator + (new File(theFilePath)).getName();
          dataDir=importDirFile + File.separator + "String_Node_Str"+ File.separator;
        }
 else {
          dataPath=importDirFile + File.separator + (new File(theFilePath)).getName();
          dataDir=importDirFile + File.separator + "String_Node_Str"+ File.separator;
        }
        if (isResume) {
          if (!theInputType.equals("String_Node_Str")) {
            (new File(dataPath)).delete();
          }
          (new File(importDirFile + File.separator + "String_Node_Str")).delete();
          FileDeleteStrategy.FORCE.delete(new File(dataDir));
          FileDeleteStrategy.FORCE.delete(new File(importDirFile + File.separator + "String_Node_Str"+ File.separator));
        }
        String sourcePath=null;
        if (theInputType.equals("String_Node_Str")) {
          OutputStream os=new FileOutputStream(dataPath);
          byte[] b=new byte[2048];
          int length;
          InputStream is=new URL(theFilePath).openStream();
          while ((length=is.read(b)) != -1) {
            os.write(b,0,length);
          }
          is.close();
          os.close();
          sourcePath=unzip(new File(dataPath),dataDir);
          FileUtils.moveDirectory(new File(sourcePath),new File(importDirFile + File.separator + "String_Node_Str"+ File.separator));
          FileDeleteStrategy.FORCE.delete(new File(dataDir));
          dataDir=importDirFile + File.separator + "String_Node_Str"+ File.separator;
        }
 else         if (theInputType.equals("String_Node_Str")) {
          sourcePath=unzip(new File(dataPath),dataDir);
          FileUtils.moveDirectory(new File(sourcePath),new File(importDirFile + File.separator + "String_Node_Str"+ File.separator));
          FileDeleteStrategy.FORCE.delete(new File(dataDir));
          dataDir=importDirFile + File.separator + "String_Node_Str"+ File.separator;
        }
        String mapFilePath=importDirFile + File.separator + "String_Node_Str";
        Collection[] finalCollections=null;
        if (theOwningCollection != null) {
          finalCollections=new Collection[otherCollections.length + 1];
          finalCollections[0]=theOwningCollection;
          for (int i=0; i < otherCollections.length; i++) {
            finalCollections[i + 1]=otherCollections[i];
          }
        }
        ItemImport myloader=new ItemImport();
        myloader.isResume=isResume;
        if (theInputType.equals("String_Node_Str") || theInputType.equals("String_Node_Str")) {
          myloader.addItems(context,finalCollections,dataDir,mapFilePath,template);
        }
 else {
          myloader.addBTEItems(context,finalCollections,theFilePath,mapFilePath,template,theInputType,dataDir);
        }
        emailSuccessMessage(context,eperson,mapFilePath);
        context.complete();
      }
 catch (      Exception e) {
        e.printStackTrace();
        String exceptionString=ExceptionUtils.getStackTrace(e);
        if (mapOut != null) {
          mapOut.close();
        }
        mapOut=null;
        try {
          File importDirFile=new File(importDir + File.separator + "String_Node_Str");
          PrintWriter errorWriter=new PrintWriter(importDirFile);
          errorWriter.print(exceptionString);
          errorWriter.close();
          emailErrorMessage(eperson,exceptionString);
          throw new Exception(e.getMessage());
        }
 catch (        Exception e2) {
        }
      }
 finally {
        if (mapOut != null) {
          mapOut.close();
        }
        try {
          context.complete();
        }
 catch (        SQLException sqle) {
          context.abort();
        }
      }
    }
  }
;
  go.isDaemon();
  go.start();
}