Program: 52068
Project: 52068
Buggy source:
/** 
 * Given an uploaded file, this method calls the method to instantiate a BTE instance to transform the input data and batch import them to DSpace
 * @param file The input file to read data from
 * @param collections The collections the created items will be inserted to
 * @param bteInputType The input type of the data (bibtex, csv, etc.)
 * @param context The context
 * @throws Exception
 */
public static void processUploadableImport(String url,Collection owningCollection,Collection[] collections,Context context) throws Exception {
  final EPerson eperson=context.getCurrentUser();
  final Collection[] otherCollections=collections;
  final Collection theOwningCollection=owningCollection;
  final String zipurl=url;
  Thread go=new Thread(){
    public void run(){
      Context context=null;
      String importDir=null;
      try {
        context=new Context();
        context.setCurrentUser(eperson);
        context.setIgnoreAuthorization(true);
        InputStream is=new URL(zipurl).openStream();
        importDir=ConfigurationManager.getProperty("String_Node_Str") + File.separator + "String_Node_Str"+ File.separator+ context.getCurrentUser().getID()+ File.separator+ (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 dataZipPath=importDirFile + File.separator + "String_Node_Str";
        String dataZipDir=importDirFile + File.separator + "String_Node_Str"+ File.separator;
        OutputStream os=new FileOutputStream(dataZipPath);
        byte[] b=new byte[2048];
        int length;
        while ((length=is.read(b)) != -1) {
          os.write(b,0,length);
        }
        is.close();
        os.close();
        ZipFile zf=new ZipFile(dataZipPath);
        ZipEntry entry;
        Enumeration<? extends ZipEntry> entries=zf.entries();
        while (entries.hasMoreElements()) {
          entry=entries.nextElement();
          if (entry.isDirectory()) {
            if (!new File(dataZipDir + entry.getName()).mkdir()) {
              log.error("String_Node_Str");
            }
          }
 else {
            int index=entry.getName().lastIndexOf('/');
            if (index == -1) {
              index=entry.getName().lastIndexOf('\\');
            }
            if (index > 0) {
              File dir=new File(dataZipDir + entry.getName().substring(0,index));
              if (!dir.mkdirs()) {
                log.error("String_Node_Str");
              }
            }
            byte[] buffer=new byte[1024];
            int len;
            InputStream in=zf.getInputStream(entry);
            BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(dataZipDir + entry.getName()));
            while ((len=in.read(buffer)) >= 0) {
              out.write(buffer,0,len);
            }
            in.close();
            out.close();
          }
        }
        zf.close();
        String sourcePath=dataZipDir;
        String mapFilePath=importDirFile + File.separator + "String_Node_Str";
        ItemImport myloader=new ItemImport();
        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];
          }
        }
        myloader.addItems(context,finalCollections,sourcePath,mapFilePath,template);
        emailSuccessMessage(context,eperson,mapFilePath);
        context.complete();
      }
 catch (      Exception e) {
        e.printStackTrace();
        if (mapOut != null) {
          mapOut.close();
        }
        mapOut=null;
        if (importDir != null) {
        }
        try {
          emailErrorMessage(eperson,e.getMessage());
          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 an uploaded file, this method calls the method to instantiate a BTE instance to transform the input data and batch import them to DSpace
 * @param file The input file to read data from
 * @param collections The collections the created items will be inserted to
 * @param bteInputType The input type of the data (bibtex, csv, etc.)
 * @param context The context
 * @throws Exception
 */
public static void processUploadableImport(String url,Collection owningCollection,String[] collections,Context context2) throws Exception {
  final EPerson eperson=context2.getCurrentUser();
  final String[] otherCollections2=collections;
  final Collection theOwningCollection=owningCollection;
  final String zipurl=url;
  Thread go=new Thread(){
    public void run(){
      Context context=null;
      String importDir=null;
      try {
        context=new Context();
        context.setCurrentUser(eperson);
        context.setIgnoreAuthorization(true);
        List<Collection> collectionList=new ArrayList<Collection>();
        if (otherCollections2 != null) {
          for (          String colID : otherCollections2) {
            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()]);
        InputStream is=new URL(zipurl).openStream();
        importDir=ConfigurationManager.getProperty("String_Node_Str") + File.separator + "String_Node_Str"+ File.separator+ context.getCurrentUser().getID()+ File.separator+ (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 dataZipPath=importDirFile + File.separator + "String_Node_Str";
        String dataZipDir=importDirFile + File.separator + "String_Node_Str"+ File.separator;
        OutputStream os=new FileOutputStream(dataZipPath);
        byte[] b=new byte[2048];
        int length;
        while ((length=is.read(b)) != -1) {
          os.write(b,0,length);
        }
        is.close();
        os.close();
        ZipFile zf=new ZipFile(dataZipPath);
        ZipEntry entry;
        Enumeration<? extends ZipEntry> entries=zf.entries();
        while (entries.hasMoreElements()) {
          entry=entries.nextElement();
          if (entry.isDirectory()) {
            if (!new File(dataZipDir + entry.getName()).mkdir()) {
              log.error("String_Node_Str");
            }
          }
 else {
            int index=entry.getName().lastIndexOf('/');
            if (index == -1) {
              index=entry.getName().lastIndexOf('\\');
            }
            if (index > 0) {
              File dir=new File(dataZipDir + entry.getName().substring(0,index));
              if (!dir.mkdirs()) {
                log.error("String_Node_Str");
              }
            }
            byte[] buffer=new byte[1024];
            int len;
            InputStream in=zf.getInputStream(entry);
            BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(dataZipDir + entry.getName()));
            while ((len=in.read(buffer)) >= 0) {
              out.write(buffer,0,len);
            }
            in.close();
            out.close();
          }
        }
        zf.close();
        String sourcePath=dataZipDir;
        String mapFilePath=importDirFile + File.separator + "String_Node_Str";
        ItemImport myloader=new ItemImport();
        myloader.isResume=false;
        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];
          }
        }
        myloader.addItems(context,finalCollections,sourcePath,mapFilePath,template);
        emailSuccessMessage(context,eperson,mapFilePath);
      }
 catch (      Exception e) {
        e.printStackTrace();
        if (mapOut != null) {
          mapOut.close();
        }
        mapOut=null;
        if (importDir != null) {
        }
        try {
          emailErrorMessage(eperson,e.getMessage());
          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();
}