Program: 73308
Project: 73308
Buggy source:
/** 
 * Returns the report design handle
 * @param request
 * @throws Exception
 * @return Report Design Handle
 */
protected IViewerReportDesignHandle getDesignHandle(HttpServletRequest request) throws Exception {
  IViewerReportDesignHandle design=null;
  IReportRunnable reportRunnable=null;
  IReportDocument reportDocumentInstance=null;
  boolean isDocumentExist=ParameterAccessor.isReportParameterExist(request,ParameterAccessor.PARAM_REPORT_DOCUMENT);
  boolean isReportExist=ParameterAccessor.isReportParameterExist(request,ParameterAccessor.PARAM_REPORT);
  if (isDocumentExist && !isReportExist) {
    boolean isValidDocument=ParameterAccessor.isValidFilePath(ParameterAccessor.getParameter(request,ParameterAccessor.PARAM_REPORT_DOCUMENT));
    if (isValidDocument) {
      reportDocumentInstance=ReportEngineService.getInstance().openReportDocument(this.reportDesignName,this.reportDocumentName,this.moduleOptions);
      if (reportDocumentInstance != null) {
        reportRunnable=reportDocumentInstance.getReportRunnable();
      }
 else {
        throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_DOCUMENT_FILE_ERROR,new String[]{this.reportDocumentName});
      }
    }
 else {
      throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_DOCUMENT_ACCESS_ERROR,new String[]{this.reportDocumentName});
    }
  }
 else   if (isReportExist) {
    if (isDocumentExist && !ParameterAccessor.isValidFilePath(ParameterAccessor.getParameter(request,ParameterAccessor.PARAM_REPORT_DOCUMENT))) {
      throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_DOCUMENT_ACCESS_ERROR,new String[]{this.reportDocumentName});
    }
    reportDocumentInstance=ReportEngineService.getInstance().openReportDocument(this.reportDesignName,this.reportDocumentName,this.moduleOptions);
    if (reportDocumentInstance != null) {
      reportRunnable=reportDocumentInstance.getReportRunnable();
    }
    if (reportRunnable == null) {
      if (!ParameterAccessor.isValidFilePath(ParameterAccessor.getParameter(request,ParameterAccessor.PARAM_REPORT))) {
        throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_REPORT_ACCESS_ERROR,new String[]{this.reportDesignName});
      }
      try {
        reportRunnable=BirtUtility.getRunnableFromDesignFile(request,this.reportDesignName,this.moduleOptions);
        if (reportRunnable == null) {
          throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_REPORT_FILE_ERROR,new String[]{this.reportDesignName});
        }
      }
 catch (      EngineException e) {
        this.exception=e;
      }
    }
  }
  if (reportDocumentInstance != null) {
    this.documentInUrl=true;
    this.parameterMap=reportDocumentInstance.getParameterValues();
    if (!reportDocumentInstance.isComplete() && isReportExist)     this.isDocumentProcessing=true;
    reportDocumentInstance.close();
  }
  if (reportRunnable != null) {
    design=new BirtViewerReportDesignHandle(IViewerReportDesignHandle.RPT_RUNNABLE_OBJECT,reportRunnable);
  }
  return design;
}

Fixed version (ground truth):
/** 
 * Returns the report design handle
 * @param request
 * @throws Exception
 * @return Report Design Handle
 */
protected IViewerReportDesignHandle getDesignHandle(HttpServletRequest request) throws Exception {
  IViewerReportDesignHandle design=null;
  IReportRunnable reportRunnable=null;
  IReportDocument reportDocumentInstance=null;
  boolean isDocumentExist=ParameterAccessor.isReportParameterExist(request,ParameterAccessor.PARAM_REPORT_DOCUMENT);
  boolean isReportExist=ParameterAccessor.isReportParameterExist(request,ParameterAccessor.PARAM_REPORT);
  if (isDocumentExist && !isReportExist) {
    boolean isValidDocument=ParameterAccessor.isValidFilePath(ParameterAccessor.getParameter(request,ParameterAccessor.PARAM_REPORT_DOCUMENT));
    if (isValidDocument) {
      reportDocumentInstance=ReportEngineService.getInstance().openReportDocument(this.reportDesignName,this.reportDocumentName,this.moduleOptions);
      if (reportDocumentInstance != null) {
        reportRunnable=reportDocumentInstance.getReportRunnable();
      }
 else {
        throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_DOCUMENT_FILE_ERROR,new String[]{this.reportDocumentName});
      }
    }
 else {
      throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_DOCUMENT_ACCESS_ERROR,new String[]{this.reportDocumentName});
    }
  }
 else   if (isReportExist) {
    if (isDocumentExist && !ParameterAccessor.isValidFilePath(ParameterAccessor.getParameter(request,ParameterAccessor.PARAM_REPORT_DOCUMENT))) {
      throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_DOCUMENT_ACCESS_ERROR,new String[]{this.reportDocumentName});
    }
    reportDocumentInstance=ReportEngineService.getInstance().openReportDocument(this.reportDesignName,this.reportDocumentName,this.moduleOptions);
    if (ParameterAccessor.isValidFilePath(ParameterAccessor.getParameter(request,ParameterAccessor.PARAM_REPORT))) {
      try {
        reportRunnable=BirtUtility.getRunnableFromDesignFile(request,this.reportDesignName,this.moduleOptions);
        if (reportRunnable == null) {
          throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_REPORT_FILE_ERROR,new String[]{this.reportDesignName});
        }
      }
 catch (      EngineException e) {
        this.exception=e;
      }
    }
  }
  if (reportDocumentInstance != null) {
    this.documentInUrl=true;
    this.parameterMap=reportDocumentInstance.getParameterValues();
    if (!reportDocumentInstance.isComplete() && isReportExist)     this.isDocumentProcessing=true;
    reportDocumentInstance.close();
  }
  if (reportRunnable != null) {
    design=new BirtViewerReportDesignHandle(IViewerReportDesignHandle.RPT_RUNNABLE_OBJECT,reportRunnable);
  }
  return design;
}