Program: 76762
Project: 76762
Buggy source:
/** 
 * Returns report design handle
 * @return IViewerReportDesignHandle
 * @throws Exception
 */
protected IViewerReportDesignHandle getDesignHandle() throws Exception {
  if (viewer == null)   return null;
  IViewerReportDesignHandle design=null;
  IReportRunnable reportRunnable=null;
  String designFile=createAbsolutePath(viewer.getReportDesign());
  String documentFile=createAbsolutePath(viewer.getReportDocument());
  HttpServletRequest request=(HttpServletRequest)pageContext.getRequest();
  boolean isValidDocument=ParameterAccessor.isValidFilePath(documentFile);
  if (isValidDocument) {
    IReportDocument reportDocumentInstance=ReportEngineService.getInstance().openReportDocument(designFile,documentFile,getModuleOptions());
    if (reportDocumentInstance != null) {
      this.documentInUrl=true;
      reportRunnable=reportDocumentInstance.getReportRunnable();
      reportDocumentInstance.close();
    }
  }
  if (reportRunnable == null) {
    if (documentFile != null && designFile == null) {
      if (isValidDocument)       throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_DOCUMENT_FILE_ERROR,new String[]{documentFile});
 else       throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_DOCUMENT_ACCESS_ERROR,new String[]{documentFile});
    }
    if (!ParameterAccessor.isValidFilePath(designFile)) {
      throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_REPORT_ACCESS_ERROR,new String[]{designFile});
    }
 else {
      File file=new File(designFile);
      if (file.exists()) {
        reportRunnable=ReportEngineService.getInstance().openReportDesign(designFile,getModuleOptions());
      }
 else       if (!ParameterAccessor.isWorkingFolderAccessOnly()) {
        InputStream is=null;
        URL url=null;
        try {
          String reportPath=designFile;
          if (!reportPath.startsWith("String_Node_Str"))           reportPath="String_Node_Str" + reportPath;
          url=request.getSession().getServletContext().getResource(reportPath);
          if (url != null)           is=url.openStream();
          if (is != null)           reportRunnable=ReportEngineService.getInstance().openReportDesign(url.toString(),is,getModuleOptions());
        }
 catch (        Exception e) {
        }
      }
      if (reportRunnable == null) {
        throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_REPORT_FILE_ERROR,new String[]{designFile});
      }
    }
  }
  if (reportRunnable != null) {
    design=new BirtViewerReportDesignHandle(IViewerReportDesignHandle.RPT_RUNNABLE_OBJECT,reportRunnable);
  }
  return design;
}

Fixed version (ground truth):
/** 
 * Returns report design handle
 * @return IViewerReportDesignHandle
 * @throws Exception
 */
protected IViewerReportDesignHandle getDesignHandle() throws Exception {
  if (viewer == null)   return null;
  IViewerReportDesignHandle design=null;
  IReportRunnable reportRunnable=null;
  String designFile=createAbsolutePath(viewer.getReportDesign());
  String documentFile=createAbsolutePath(viewer.getReportDocument());
  HttpServletRequest request=(HttpServletRequest)pageContext.getRequest();
  boolean isValidDocument=ParameterAccessor.isValidFilePath(documentFile);
  if (documentFile != null && isValidDocument) {
    IReportDocument reportDocumentInstance=ReportEngineService.getInstance().openReportDocument(designFile,documentFile,getModuleOptions());
    if (reportDocumentInstance != null) {
      this.documentInUrl=true;
      reportRunnable=reportDocumentInstance.getReportRunnable();
      reportDocumentInstance.close();
    }
  }
  if (reportRunnable == null) {
    if (documentFile != null && designFile == null) {
      if (isValidDocument)       throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_DOCUMENT_FILE_ERROR,new String[]{documentFile});
 else       throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_DOCUMENT_ACCESS_ERROR,new String[]{documentFile});
    }
    if (!ParameterAccessor.isValidFilePath(designFile)) {
      throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_REPORT_ACCESS_ERROR,new String[]{designFile});
    }
 else {
      File file=new File(designFile);
      if (file.exists()) {
        reportRunnable=ReportEngineService.getInstance().openReportDesign(designFile,getModuleOptions());
      }
 else       if (!ParameterAccessor.isWorkingFolderAccessOnly()) {
        InputStream is=null;
        URL url=null;
        try {
          String reportPath=viewer.getReportDesign();
          if (!reportPath.startsWith("String_Node_Str"))           reportPath="String_Node_Str" + reportPath;
          url=request.getSession().getServletContext().getResource(reportPath);
          if (url != null)           is=url.openStream();
          if (is != null)           reportRunnable=ReportEngineService.getInstance().openReportDesign(url.toString(),is,getModuleOptions());
        }
 catch (        Exception e) {
        }
      }
      if (reportRunnable == null) {
        throw new ViewerException(ResourceConstants.GENERAL_EXCEPTION_REPORT_FILE_ERROR,new String[]{designFile});
      }
    }
  }
  if (reportRunnable != null) {
    design=new BirtViewerReportDesignHandle(IViewerReportDesignHandle.RPT_RUNNABLE_OBJECT,reportRunnable);
  }
  return design;
}