Program: 15582
Project: 15582
Buggy source:
protected TemplateModel createModel(ObjectWrapper objectWrapper,ServletContext servletContext,final HttpServletRequest request,final HttpServletResponse response) throws TemplateModelException {
  try {
    AllHttpScopesHashModel params=new AllHttpScopesHashModel(objectWrapper,servletContext,request);
    ServletContextHashModel servletContextModel=(ServletContextHashModel)servletContext.getAttribute(ATTR_APPLICATION_MODEL);
    if (servletContextModel == null) {
      servletContextModel=new ServletContextHashModel(this,objectWrapper);
      servletContext.setAttribute(ATTR_APPLICATION_MODEL,servletContextModel);
      TaglibFactory taglibFactory=createTaglibFactory(objectWrapper,servletContext);
      servletContext.setAttribute(ATTR_JSP_TAGLIBS_MODEL,taglibFactory);
      initializeServletContext(request,response);
    }
    params.putUnlistedModel(KEY_APPLICATION,servletContextModel);
    params.putUnlistedModel(KEY_APPLICATION_PRIVATE,servletContextModel);
    params.putUnlistedModel(KEY_JSP_TAGLIBS,(TemplateModel)servletContext.getAttribute(ATTR_JSP_TAGLIBS_MODEL));
    HttpSessionHashModel sessionModel;
    HttpSession session=request.getSession(false);
    if (session != null) {
      sessionModel=(HttpSessionHashModel)session.getAttribute(ATTR_SESSION_MODEL);
      if (sessionModel == null || sessionModel.isOrphaned(session)) {
        sessionModel=new HttpSessionHashModel(session,objectWrapper);
        initializeSessionAndInstallModel(request,response,sessionModel,session);
      }
    }
 else {
      sessionModel=new HttpSessionHashModel(this,request,response,objectWrapper);
    }
    params.putUnlistedModel(KEY_SESSION,sessionModel);
    HttpRequestHashModel requestModel=(HttpRequestHashModel)request.getAttribute(ATTR_REQUEST_MODEL);
    if (requestModel == null || requestModel.getRequest() != request) {
      requestModel=new HttpRequestHashModel(request,response,objectWrapper);
      request.setAttribute(ATTR_REQUEST_MODEL,requestModel);
      request.setAttribute(ATTR_REQUEST_PARAMETERS_MODEL,createRequestParametersHashModel(request));
    }
    params.putUnlistedModel(KEY_REQUEST,requestModel);
    params.putUnlistedModel(KEY_INCLUDE,new IncludePage(request,response));
    params.putUnlistedModel(KEY_REQUEST_PRIVATE,requestModel);
    HttpRequestParametersHashModel requestParametersModel=(HttpRequestParametersHashModel)request.getAttribute(ATTR_REQUEST_PARAMETERS_MODEL);
    params.putUnlistedModel(KEY_REQUEST_PARAMETERS,requestParametersModel);
    return params;
  }
 catch (  ServletException e) {
    throw new TemplateModelException(e);
  }
catch (  IOException e) {
    throw new TemplateModelException(e);
  }
}

Fixed version (ground truth):
protected TemplateModel createModel(ObjectWrapper objectWrapper,ServletContext servletContext,final HttpServletRequest request,final HttpServletResponse response) throws TemplateModelException {
  try {
    AllHttpScopesHashModel params=new AllHttpScopesHashModel(objectWrapper,servletContext,request);
    final ServletContextHashModel servletContextModel;
    final TaglibFactory taglibFactory;
synchronized (lazyInitFieldsLock) {
      if (this.servletContextModel == null) {
        servletContextModel=new ServletContextHashModel(this,objectWrapper);
        taglibFactory=createTaglibFactory(objectWrapper,servletContext);
        servletContext.setAttribute(ATTR_APPLICATION_MODEL,servletContextModel);
        servletContext.setAttribute(ATTR_JSP_TAGLIBS_MODEL,taglibFactory);
        initializeServletContext(request,response);
        this.taglibFactory=taglibFactory;
        this.servletContextModel=servletContextModel;
      }
 else {
        servletContextModel=this.servletContextModel;
        taglibFactory=this.taglibFactory;
      }
    }
    params.putUnlistedModel(KEY_APPLICATION,servletContextModel);
    params.putUnlistedModel(KEY_APPLICATION_PRIVATE,servletContextModel);
    params.putUnlistedModel(KEY_JSP_TAGLIBS,taglibFactory);
    HttpSessionHashModel sessionModel;
    HttpSession session=request.getSession(false);
    if (session != null) {
      sessionModel=(HttpSessionHashModel)session.getAttribute(ATTR_SESSION_MODEL);
      if (sessionModel == null || sessionModel.isOrphaned(session)) {
        sessionModel=new HttpSessionHashModel(session,objectWrapper);
        initializeSessionAndInstallModel(request,response,sessionModel,session);
      }
    }
 else {
      sessionModel=new HttpSessionHashModel(this,request,response,objectWrapper);
    }
    params.putUnlistedModel(KEY_SESSION,sessionModel);
    HttpRequestHashModel requestModel=(HttpRequestHashModel)request.getAttribute(ATTR_REQUEST_MODEL);
    if (requestModel == null || requestModel.getRequest() != request) {
      requestModel=new HttpRequestHashModel(request,response,objectWrapper);
      request.setAttribute(ATTR_REQUEST_MODEL,requestModel);
      request.setAttribute(ATTR_REQUEST_PARAMETERS_MODEL,createRequestParametersHashModel(request));
    }
    params.putUnlistedModel(KEY_REQUEST,requestModel);
    params.putUnlistedModel(KEY_INCLUDE,new IncludePage(request,response));
    params.putUnlistedModel(KEY_REQUEST_PRIVATE,requestModel);
    HttpRequestParametersHashModel requestParametersModel=(HttpRequestParametersHashModel)request.getAttribute(ATTR_REQUEST_PARAMETERS_MODEL);
    params.putUnlistedModel(KEY_REQUEST_PARAMETERS,requestParametersModel);
    return params;
  }
 catch (  ServletException e) {
    throw new TemplateModelException(e);
  }
catch (  IOException e) {
    throw new TemplateModelException(e);
  }
}