Program: 115299
Project: 115299
Buggy source:
/** 
 * Uploads the excel version file
 * @param version
 * @throws Exception
 */
public String uploadFile(String theDir,CRFVersionBean version) throws Exception {
  List<File> theFiles=uploadHelper.returnFiles(request,context,theDir);
  errors.remove("String_Node_Str");
  String tempFile=null;
  for (  File f : theFiles) {
    if (f == null || f.getName() == null) {
      logger.info("String_Node_Str");
      Validator.addError(errors,"String_Node_Str",resword.getString("String_Node_Str"));
      session.setAttribute("String_Node_Str",version);
      return tempFile;
    }
 else     if (f.getName().indexOf("String_Node_Str") < 0 && f.getName().indexOf("String_Node_Str") < 0) {
      logger.info("String_Node_Str" + f.getName());
      addPageMessage(respage.getString("String_Node_Str"));
      session.setAttribute("String_Node_Str",version);
      return tempFile;
    }
 else {
      logger.info("String_Node_Str" + f.getName());
      tempFile=f.getName();
      FileInputStream inStream=null;
      FileInputStream inStreamClassic=null;
      SpreadSheetTableRepeating htab=null;
      SpreadSheetTableClassic sstc=null;
      NewCRFBean nib=null;
      try {
        inStream=new FileInputStream(theDir + tempFile);
        htab=new SpreadSheetTableRepeating(inStream,ub,version.getName(),request.getLocale(),currentStudy.getId());
        htab.setMeasurementUnitDao((MeasurementUnitDao)SpringServletAccess.getApplicationContext(context).getBean("String_Node_Str"));
        if (!htab.isRepeating()) {
          inStreamClassic=new FileInputStream(theDir + tempFile);
          sstc=new SpreadSheetTableClassic(inStreamClassic,ub,version.getName(),request.getLocale(),currentStudy.getId());
          sstc.setMeasurementUnitDao((MeasurementUnitDao)SpringServletAccess.getApplicationContext(context).getBean("String_Node_Str"));
        }
        if (htab.isRepeating()) {
          htab.setCrfId(version.getCrfId());
          session.setAttribute("String_Node_Str","String_Node_Str");
        }
 else {
          sstc.setCrfId(version.getCrfId());
        }
        if (htab.isRepeating()) {
          nib=htab.toNewCRF(sm.getDataSource(),respage);
        }
 else {
          nib=sstc.toNewCRF(sm.getDataSource(),respage);
        }
        HSSFWorkbook workbook=null;
        FileInputStream inputStream=null;
        try {
          inputStream=new FileInputStream(theDir + tempFile);
          workbook=new HSSFWorkbook(inputStream);
          Preview preview;
          if (htab.isRepeating()) {
            preview=new SpreadsheetPreviewNw();
          }
 else {
            preview=new SpreadsheetPreview();
          }
          session.setAttribute("String_Node_Str",preview.createCrfMetaObject(workbook));
        }
 catch (        Exception exc) {
          exc.printStackTrace();
          String message=resword.getString("String_Node_Str");
          logger.info(message + "String_Node_Str" + exc.getMessage());
          this.addPageMessage(message);
        }
 finally {
          if (inputStream != null) {
            try {
              inputStream.close();
            }
 catch (            IOException io) {
            }
          }
        }
        ArrayList ibs=isItemSame(nib.getItems(),version);
        if (!ibs.isEmpty()) {
          ArrayList warnings=new ArrayList();
          warnings.add(resexception.getString("String_Node_Str"));
          for (int i=0; i < ibs.size(); i++) {
            ItemBean ib=(ItemBean)ibs.get(i);
            if (ib.getOwner().getId() == ub.getId()) {
              warnings.add(resword.getString("String_Node_Str") + "String_Node_Str" + ib.getName()+ "String_Node_Str"+ resexception.getString("String_Node_Str")+ ib.getDescription()+ "String_Node_Str"+ ib.getDataType().getName()+ "String_Node_Str"+ ib.getUnits()+ "String_Node_Str"+ resword.getString("String_Node_Str")+ "String_Node_Str"+ ib.isPhiStatus()+ "String_Node_Str"+ resword.getString("String_Node_Str")+ "String_Node_Str"+ resexception.getString("String_Node_Str")+ "String_Node_Str"+ resexception.getString("String_Node_Str"));
            }
 else {
              warnings.add(resword.getString("String_Node_Str") + "String_Node_Str" + ib.getName()+ "String_Node_Str"+ resexception.getString("String_Node_Str")+ ib.getDescription()+ "String_Node_Str"+ "String_Node_Str"+ ib.getDataType().getName()+ "String_Node_Str"+ "String_Node_Str"+ ib.getUnits()+ "String_Node_Str"+ resword.getString("String_Node_Str")+ "String_Node_Str"+ ib.isPhiStatus()+ "String_Node_Str"+ resexception.getString("String_Node_Str"));
            }
            request.setAttribute("String_Node_Str",warnings);
          }
        }
        ItemBean ib=isResponseValid(nib.getItems(),version);
        if (ib != null) {
          nib.getErrors().add(resword.getString("String_Node_Str") + "String_Node_Str" + ib.getName()+ "String_Node_Str"+ resexception.getString("String_Node_Str"));
        }
      }
 catch (      IOException io) {
        logger.warn("String_Node_Str" + io.getMessage());
      }
 finally {
        if (inStream != null) {
          try {
            inStream.close();
          }
 catch (          IOException ioe) {
          }
        }
        if (inStreamClassic != null) {
          try {
            inStreamClassic.close();
          }
 catch (          IOException ioe) {
          }
        }
      }
      session.setAttribute("String_Node_Str",nib.getErrors());
      session.setAttribute("String_Node_Str",nib.getHtmlTable());
      session.setAttribute("String_Node_Str",nib);
    }
  }
  return tempFile;
}

Fixed version (ground truth):
/** 
 * Uploads the excel version file
 * @param version
 * @throws Exception
 */
public String uploadFile(String theDir,CRFVersionBean version) throws Exception {
  List<File> theFiles=uploadHelper.returnFiles(request,context,theDir);
  errors.remove("String_Node_Str");
  String tempFile=null;
  for (  File f : theFiles) {
    if (f == null || f.getName() == null) {
      logger.info("String_Node_Str");
      Validator.addError(errors,"String_Node_Str",resword.getString("String_Node_Str"));
      session.setAttribute("String_Node_Str",version);
      return tempFile;
    }
 else     if (f.getName().indexOf("String_Node_Str") < 0 && f.getName().indexOf("String_Node_Str") < 0) {
      logger.info("String_Node_Str" + f.getName());
      Validator.addError(errors,"String_Node_Str",respage.getString("String_Node_Str"));
      session.setAttribute("String_Node_Str",version);
      return tempFile;
    }
 else {
      logger.info("String_Node_Str" + f.getName());
      tempFile=f.getName();
      FileInputStream inStream=null;
      FileInputStream inStreamClassic=null;
      SpreadSheetTableRepeating htab=null;
      SpreadSheetTableClassic sstc=null;
      NewCRFBean nib=null;
      try {
        inStream=new FileInputStream(theDir + tempFile);
        htab=new SpreadSheetTableRepeating(inStream,ub,version.getName(),request.getLocale(),currentStudy.getId());
        htab.setMeasurementUnitDao((MeasurementUnitDao)SpringServletAccess.getApplicationContext(context).getBean("String_Node_Str"));
        if (!htab.isRepeating()) {
          inStreamClassic=new FileInputStream(theDir + tempFile);
          sstc=new SpreadSheetTableClassic(inStreamClassic,ub,version.getName(),request.getLocale(),currentStudy.getId());
          sstc.setMeasurementUnitDao((MeasurementUnitDao)SpringServletAccess.getApplicationContext(context).getBean("String_Node_Str"));
        }
        if (htab.isRepeating()) {
          htab.setCrfId(version.getCrfId());
          session.setAttribute("String_Node_Str","String_Node_Str");
        }
 else {
          sstc.setCrfId(version.getCrfId());
        }
        if (htab.isRepeating()) {
          nib=htab.toNewCRF(sm.getDataSource(),respage);
        }
 else {
          nib=sstc.toNewCRF(sm.getDataSource(),respage);
        }
        HSSFWorkbook workbook=null;
        FileInputStream inputStream=null;
        try {
          inputStream=new FileInputStream(theDir + tempFile);
          workbook=new HSSFWorkbook(inputStream);
          Preview preview;
          if (htab.isRepeating()) {
            preview=new SpreadsheetPreviewNw();
          }
 else {
            preview=new SpreadsheetPreview();
          }
          session.setAttribute("String_Node_Str",preview.createCrfMetaObject(workbook));
        }
 catch (        Exception exc) {
          exc.printStackTrace();
          String message=resword.getString("String_Node_Str");
          logger.info(message + "String_Node_Str" + exc.getMessage());
          this.addPageMessage(message);
        }
 finally {
          if (inputStream != null) {
            try {
              inputStream.close();
            }
 catch (            IOException io) {
            }
          }
        }
        ArrayList ibs=isItemSame(nib.getItems(),version);
        if (!ibs.isEmpty()) {
          ArrayList warnings=new ArrayList();
          warnings.add(resexception.getString("String_Node_Str"));
          for (int i=0; i < ibs.size(); i++) {
            ItemBean ib=(ItemBean)ibs.get(i);
            if (ib.getOwner().getId() == ub.getId()) {
              warnings.add(resword.getString("String_Node_Str") + "String_Node_Str" + ib.getName()+ "String_Node_Str"+ resexception.getString("String_Node_Str")+ ib.getDescription()+ "String_Node_Str"+ ib.getDataType().getName()+ "String_Node_Str"+ ib.getUnits()+ "String_Node_Str"+ resword.getString("String_Node_Str")+ "String_Node_Str"+ ib.isPhiStatus()+ "String_Node_Str"+ resword.getString("String_Node_Str")+ "String_Node_Str"+ resexception.getString("String_Node_Str")+ "String_Node_Str"+ resexception.getString("String_Node_Str"));
            }
 else {
              warnings.add(resword.getString("String_Node_Str") + "String_Node_Str" + ib.getName()+ "String_Node_Str"+ resexception.getString("String_Node_Str")+ ib.getDescription()+ "String_Node_Str"+ "String_Node_Str"+ ib.getDataType().getName()+ "String_Node_Str"+ "String_Node_Str"+ ib.getUnits()+ "String_Node_Str"+ resword.getString("String_Node_Str")+ "String_Node_Str"+ ib.isPhiStatus()+ "String_Node_Str"+ resexception.getString("String_Node_Str"));
            }
            request.setAttribute("String_Node_Str",warnings);
          }
        }
        ItemBean ib=isResponseValid(nib.getItems(),version);
        if (ib != null) {
          nib.getErrors().add(resword.getString("String_Node_Str") + "String_Node_Str" + ib.getName()+ "String_Node_Str"+ resexception.getString("String_Node_Str"));
        }
      }
 catch (      IOException io) {
        logger.warn("String_Node_Str" + io.getMessage());
      }
 finally {
        if (inStream != null) {
          try {
            inStream.close();
          }
 catch (          IOException ioe) {
          }
        }
        if (inStreamClassic != null) {
          try {
            inStreamClassic.close();
          }
 catch (          IOException ioe) {
          }
        }
      }
      session.setAttribute("String_Node_Str",nib.getErrors());
      session.setAttribute("String_Node_Str",nib.getHtmlTable());
      session.setAttribute("String_Node_Str",nib);
    }
  }
  return tempFile;
}