Program: 70013
Project: 70013
Buggy source:
/** 
 * intialize the render options used to render the report. the render options are load from: <li> engine level default options</li> <li> engine level format options</li> <li> engine level emitter options</li> <li> task level options </li>
 * @throws EngineException 
 */
protected void setupRenderOption() throws EngineException {
  ExtensionManager extManager=ExtensionManager.getInstance();
  if (renderOptions != null) {
    format=renderOptions.getOutputFormat();
    emitterID=renderOptions.getEmitterID();
    if (emitterID == null) {
      if (format == null) {
        format=RenderOption.OUTPUT_FORMAT_HTML;
        renderOptions.setOutputFormat(format);
      }
      emitterID=engine.getConfig().getDefaultEmitter(format);
    }
    if (emitterID != null) {
      if (!extManager.isValidEmitterID(emitterID)) {
        log.log(Level.SEVERE,MessageConstants.INVALID_EMITTER_ID,emitterID);
        throw new EngineException(MessageConstants.INVALID_EMITTER_ID,emitterID);
      }
      String formatOfEmitter=extManager.getFormat(emitterID);
      if (null == format) {
        renderOptions.setOutputFormat(formatOfEmitter);
      }
 else       if (!format.equals(formatOfEmitter)) {
        throw new EngineException(MessageConstants.FORMAT_NOT_SUPPORTED_EXCEPTION,format);
      }
    }
 else {
      if (format == null) {
        format=RenderOption.OUTPUT_FORMAT_HTML;
        renderOptions.setOutputFormat(format);
        emitterID=RenderOption.OUTPUT_EMITTERID_HTML;
      }
 else {
        String innerFormat=extManager.getSupportedFormat(format);
        if (innerFormat == null) {
          log.log(Level.SEVERE,MessageConstants.FORMAT_NOT_SUPPORTED_EXCEPTION,format);
          throw new UnsupportedFormatException(MessageConstants.FORMAT_NOT_SUPPORTED_EXCEPTION,format);
        }
 else {
          renderOptions.setOutputFormat(innerFormat);
          format=innerFormat;
          emitterID=extManager.getEmitterID(format);
        }
      }
    }
  }
  Map appContext=executionContext.getAppContext();
  if (IRenderOption.OUTPUT_EMITTERID_PDF.equals(emitterID)) {
    Object renderContext=appContext.get(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT);
    if (renderContext instanceof PDFRenderContext) {
      PDFRenderContext pdfContext=(PDFRenderContext)renderContext;
      mergeOption(renderOptions,PDFRenderOption.BASE_URL,pdfContext.getBaseURL());
      mergeOption(renderOptions,PDFRenderOption.FONT_DIRECTORY,pdfContext.getFontDirectory());
      mergeOption(renderOptions,PDFRenderOption.SUPPORTED_IMAGE_FORMATS,pdfContext.getSupportedImageFormats());
      mergeOption(renderOptions,PDFRenderOption.IS_EMBEDDED_FONT,new Boolean(pdfContext.isEmbededFont()));
    }
  }
 else {
    Object renderContext=appContext.get(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT);
    if (renderContext instanceof HTMLRenderContext) {
      HTMLRenderContext htmlContext=(HTMLRenderContext)renderContext;
      mergeOption(renderOptions,HTMLRenderOption.BASE_IMAGE_URL,htmlContext.getBaseImageURL());
      mergeOption(renderOptions,HTMLRenderOption.BASE_URL,htmlContext.getBaseURL());
      mergeOption(renderOptions,HTMLRenderOption.IMAGE_DIRECTROY,htmlContext.getImageDirectory());
      if (FORMAT_HTML.equals(format)) {
        mergeOption(renderOptions,HTMLRenderOption.SUPPORTED_IMAGE_FORMATS,htmlContext.getSupportedImageFormats());
      }
    }
  }
  HashMap options=new HashMap();
  HashMap configs=engine.getConfig().getEmitterConfigs();
  IRenderOption defaultOptions=(IRenderOption)configs.get(IEngineConfig.DEFAULT_RENDER_OPTION);
  if (defaultOptions == null) {
    defaultOptions=(IRenderOption)configs.get(IRenderOption.OUTPUT_FORMAT_HTML);
  }
  if (defaultOptions != null) {
    options.putAll(defaultOptions.getOptions());
  }
  IRenderOption formatOptions=(IRenderOption)configs.get(format);
  if (formatOptions != null) {
    options.putAll(formatOptions.getOptions());
  }
  if (emitterID != null) {
    IRenderOption emitterOptions=(IRenderOption)configs.get(emitterID);
    if (emitterOptions != null) {
      options.putAll(emitterOptions.getOptions());
    }
  }
  if (renderOptions != null) {
    options.putAll(renderOptions.getOptions());
  }
  IRenderOption allOptions=new RenderOption(options);
  executionContext.setRenderOption(allOptions);
  if (IRenderOption.OUTPUT_EMITTERID_PDF.equals(emitterID)) {
    Object renderContext=appContext.get(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT);
    if (renderContext == null) {
      PDFRenderOption pdfOptions=new PDFRenderOption(allOptions);
      PDFRenderContext pdfContext=new PDFRenderContext();
      pdfContext.setBaseURL(pdfOptions.getBaseURL());
      pdfContext.setEmbededFont(pdfOptions.isEmbededFont());
      pdfContext.setFontDirectory(pdfOptions.getFontDirectory());
      pdfContext.setSupportedImageFormats(pdfOptions.getSupportedImageFormats());
      appContext.put(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT,pdfContext);
    }
  }
 else {
    Object renderContext=appContext.get(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT);
    if (renderContext == null) {
      HTMLRenderContext htmlContext=new HTMLRenderContext();
      HTMLRenderOption htmlOptions=new HTMLRenderOption(allOptions);
      htmlContext.setBaseImageURL(htmlOptions.getBaseImageURL());
      htmlContext.setBaseURL(htmlOptions.getBaseURL());
      htmlContext.setImageDirectory(htmlOptions.getImageDirectory());
      htmlContext.setSupportedImageFormats(htmlOptions.getSupportedImageFormats());
      htmlContext.SetRenderOption(allOptions);
      appContext.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,htmlContext);
    }
  }
}

Fixed version (ground truth):
/** 
 * intialize the render options used to render the report. the render options are load from: <li> engine level default options</li> <li> engine level format options</li> <li> engine level emitter options</li> <li> task level options </li>
 * @throws EngineException 
 */
protected void setupRenderOption() throws EngineException {
  ExtensionManager extManager=ExtensionManager.getInstance();
  if (renderOptions != null) {
    format=renderOptions.getOutputFormat();
    emitterID=renderOptions.getEmitterID();
    if (emitterID == null) {
      if (format == null) {
        format=RenderOption.OUTPUT_FORMAT_HTML;
        renderOptions.setOutputFormat(format);
      }
      emitterID=engine.getConfig().getDefaultEmitter(format);
    }
    if (emitterID != null) {
      if (!extManager.isValidEmitterID(emitterID)) {
        log.log(Level.SEVERE,MessageConstants.INVALID_EMITTER_ID,emitterID);
        throw new EngineException(MessageConstants.INVALID_EMITTER_ID,emitterID);
      }
      String formatOfEmitter=extManager.getFormat(emitterID);
      if (null == format) {
        renderOptions.setOutputFormat(formatOfEmitter);
      }
 else       if (!format.equalsIgnoreCase(formatOfEmitter)) {
        throw new EngineException(MessageConstants.FORMAT_NOT_SUPPORTED_EXCEPTION,format);
      }
    }
 else {
      if (format == null) {
        format=RenderOption.OUTPUT_FORMAT_HTML;
        renderOptions.setOutputFormat(format);
        emitterID=RenderOption.OUTPUT_EMITTERID_HTML;
      }
 else {
        String innerFormat=extManager.getSupportedFormat(format);
        if (innerFormat == null) {
          log.log(Level.SEVERE,MessageConstants.FORMAT_NOT_SUPPORTED_EXCEPTION,format);
          throw new UnsupportedFormatException(MessageConstants.FORMAT_NOT_SUPPORTED_EXCEPTION,format);
        }
 else {
          renderOptions.setOutputFormat(innerFormat);
          format=innerFormat;
          emitterID=extManager.getEmitterID(format);
        }
      }
    }
  }
  Map appContext=executionContext.getAppContext();
  if (IRenderOption.OUTPUT_EMITTERID_PDF.equals(emitterID)) {
    Object renderContext=appContext.get(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT);
    if (renderContext instanceof PDFRenderContext) {
      PDFRenderContext pdfContext=(PDFRenderContext)renderContext;
      mergeOption(renderOptions,PDFRenderOption.BASE_URL,pdfContext.getBaseURL());
      mergeOption(renderOptions,PDFRenderOption.FONT_DIRECTORY,pdfContext.getFontDirectory());
      mergeOption(renderOptions,PDFRenderOption.SUPPORTED_IMAGE_FORMATS,pdfContext.getSupportedImageFormats());
      mergeOption(renderOptions,PDFRenderOption.IS_EMBEDDED_FONT,new Boolean(pdfContext.isEmbededFont()));
    }
  }
 else {
    Object renderContext=appContext.get(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT);
    if (renderContext instanceof HTMLRenderContext) {
      HTMLRenderContext htmlContext=(HTMLRenderContext)renderContext;
      mergeOption(renderOptions,HTMLRenderOption.BASE_IMAGE_URL,htmlContext.getBaseImageURL());
      mergeOption(renderOptions,HTMLRenderOption.BASE_URL,htmlContext.getBaseURL());
      mergeOption(renderOptions,HTMLRenderOption.IMAGE_DIRECTROY,htmlContext.getImageDirectory());
      if (FORMAT_HTML.equals(format)) {
        mergeOption(renderOptions,HTMLRenderOption.SUPPORTED_IMAGE_FORMATS,htmlContext.getSupportedImageFormats());
      }
    }
  }
  HashMap options=new HashMap();
  HashMap configs=engine.getConfig().getEmitterConfigs();
  IRenderOption defaultOptions=(IRenderOption)configs.get(IEngineConfig.DEFAULT_RENDER_OPTION);
  if (defaultOptions == null) {
    defaultOptions=(IRenderOption)configs.get(IRenderOption.OUTPUT_FORMAT_HTML);
  }
  if (defaultOptions != null) {
    options.putAll(defaultOptions.getOptions());
  }
  IRenderOption formatOptions=(IRenderOption)configs.get(format);
  if (formatOptions != null) {
    options.putAll(formatOptions.getOptions());
  }
  if (emitterID != null) {
    IRenderOption emitterOptions=(IRenderOption)configs.get(emitterID);
    if (emitterOptions != null) {
      options.putAll(emitterOptions.getOptions());
    }
  }
  if (renderOptions != null) {
    options.putAll(renderOptions.getOptions());
  }
  IRenderOption allOptions=new RenderOption(options);
  executionContext.setRenderOption(allOptions);
  if (IRenderOption.OUTPUT_EMITTERID_PDF.equals(emitterID)) {
    Object renderContext=appContext.get(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT);
    if (renderContext == null) {
      PDFRenderOption pdfOptions=new PDFRenderOption(allOptions);
      PDFRenderContext pdfContext=new PDFRenderContext();
      pdfContext.setBaseURL(pdfOptions.getBaseURL());
      pdfContext.setEmbededFont(pdfOptions.isEmbededFont());
      pdfContext.setFontDirectory(pdfOptions.getFontDirectory());
      pdfContext.setSupportedImageFormats(pdfOptions.getSupportedImageFormats());
      appContext.put(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT,pdfContext);
    }
  }
 else {
    Object renderContext=appContext.get(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT);
    if (renderContext == null) {
      HTMLRenderContext htmlContext=new HTMLRenderContext();
      HTMLRenderOption htmlOptions=new HTMLRenderOption(allOptions);
      htmlContext.setBaseImageURL(htmlOptions.getBaseImageURL());
      htmlContext.setBaseURL(htmlOptions.getBaseURL());
      htmlContext.setImageDirectory(htmlOptions.getImageDirectory());
      htmlContext.setSupportedImageFormats(htmlOptions.getSupportedImageFormats());
      htmlContext.SetRenderOption(allOptions);
      appContext.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,htmlContext);
    }
  }
}