title: Stackoverflow error in JSF 2 on WebLogic 12c
body: <p>I'm working on an application that is a mix of legacy JSP servlet code and newer JSF code. I am encountering a StackOverlow error that I can't solve. Has anyone seen or experienced anything similar and can help point me in the right direction on this type of hybrid JSP/JSF application?</p>
  
  <p>I'm pretty sure that the JSF framework is trying to do something on a non-JSF page and is getting caught in a recursive loop inside the JSF framework. I'm using JSF 2.1.20 on a clustered WebLogic 12.1.3 environment. I'm not bundling any of the JSF libraries in my EAR or WAR files, I'm using the server versions of everything.</p>
  
  <p>I've done a fair bit of searching and found other similar issues but none of the solutions has made any difference to me so far. The main difference seems to be that my error is pretty random and doesn't happen all the time or in the same place or on the same objects.</p>
  
  <p>My stack trace is below... once I get to the "Caused by" section I can see the same lines repeating over and over indicating my application is trying to find or do something with JSF and failing. I didn't paste the whole stack trace because it just keeps repeating lines 286 to 143 over 1000+ times until the stack finally fills up and throws out the error.</p>
  
  <pre><code>2017-07-05 10:06:00,133 [[ACTIVE] ExecuteThread: '11' for queue: 'weblogic.kernel.Default (self-tuning)'] FATAL SecurityFilter        Msg=[EVENT FAILURE xxxxxxx -&gt; /SecurityFilter] Error in ESAPI security filter: java.lang.StackOverflowError  UserId=xxxxxxx
  javax.servlet.ServletException: java.lang.StackOverflowError
      at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:387)
      at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:243)
      at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:600)
      at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:275)
      at myapp.pkg.AcctSummaryAction.perform(AcctSummaryAction.java:158)
      at myapp.pkg.DispatcherSec.processRequest(DispatcherSec.java:119)
      at myapp.pkg.DispatcherSec.doGet(DispatcherSec.java:130)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
      at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
      at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
      at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
      at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)
      at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at myapp.navigation.JsfRequestFilter.doFilter(JsfRequestFilter.java:187)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at myapp.esapi.filters.SecurityFilter.doFilter(SecurityFilter.java:147)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at myapp.common.MdcFilter.doFilter(MdcFilter.java:68)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at myapp.navigation.DisplayProcessingFilter.doFilter(DisplayProcessingFilter.java:118)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at myapp.common.NoCacheFilter.doFilter(NoCacheFilter.java:68)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3431)
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3397)
      at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
      at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
      at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
      at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2280)
      at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2196)
      at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174)
      at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1621)
      at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:256)
      at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
      at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)
  Caused by: java.lang.StackOverflowError
      at javax.faces.context.FacesContext.getCurrentInstance(FacesContext.java:832)
      at javax.faces.FactoryFinder$FactoryManagerCache.getApplicationFactoryManager(FactoryFinder.java:715)
      at javax.faces.FactoryFinder$FactoryManagerCache.access$100(FactoryFinder.java:690)
      at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:340)
      at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:141)
      at com.sun.faces.util.MessageFactory.getApplication(MessageFactory.java:286)
      at com.sun.faces.util.MessageFactory.getMessage(MessageFactory.java:158)
      at com.sun.faces.util.MessageFactory.getMessage(MessageFactory.java:136)
      at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:386)
      at com.sun.faces.application.ApplicationAssociate.&lt;init&gt;(ApplicationAssociate.java:203)
      at com.sun.faces.application.ApplicationImpl.&lt;init&gt;(ApplicationImpl.java:214)
      at com.sun.faces.application.ApplicationFactoryImpl.getApplication(ApplicationFactoryImpl.java:107)
      at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:143)
      at com.sun.faces.util.MessageFactory.getApplication(MessageFactory.java:286)
      at com.sun.faces.util.MessageFactory.getMessage(MessageFactory.java:158)
      at com.sun.faces.util.MessageFactory.getMessage(MessageFactory.java:136)
      at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:386)
      at com.sun.faces.application.ApplicationAssociate.&lt;init&gt;(ApplicationAssociate.java:203)
      at com.sun.faces.application.ApplicationImpl.&lt;init&gt;(ApplicationImpl.java:214)
      at com.sun.faces.application.ApplicationFactoryImpl.getApplication(ApplicationFactoryImpl.java:107)
      at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:143)
      at com.sun.faces.util.MessageFactory.getApplication(MessageFactory.java:286)
      at com.sun.faces.util.MessageFactory.getMessage(MessageFactory.java:158)
      at com.sun.faces.util.MessageFactory.getMessage(MessageFactory.java:136)
      at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:386)
      at com.sun.faces.application.ApplicationAssociate.&lt;init&gt;(ApplicationAssociate.java:203)
      at com.sun.faces.application.ApplicationImpl.&lt;init&gt;(ApplicationImpl.java:214)
      at com.sun.faces.application.ApplicationFactoryImpl.getApplication(ApplicationFactoryImpl.java:107)
      at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:143)
      at com.sun.faces.util.MessageFactory.getApplication(MessageFactory.java:286)
      at com.sun.faces.util.MessageFactory.getMessage(MessageFactory.java:158)
      at com.sun.faces.util.MessageFactory.getMessage(MessageFactory.java:136)
      at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:386)
      at com.sun.faces.application.ApplicationAssociate.&lt;init&gt;(ApplicationAssociate.java:203)
      at com.sun.faces.application.ApplicationImpl.&lt;init&gt;(ApplicationImpl.java:214)
      at com.sun.faces.application.ApplicationFactoryImpl.getApplication(ApplicationFactoryImpl.java:107)
      at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:143)
      at com.sun.faces.util.MessageFactory.getApplication(MessageFactory.java:286)
      at com.sun.faces.util.MessageFactory.getMessage(MessageFactory.java:158)
      at com.sun.faces.util.MessageFactory.getMessage(MessageFactory.java:136)
      at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:386)
      at com.sun.faces.application.ApplicationAssociate.&lt;init&gt;(ApplicationAssociate.java:203)
      at com.sun.faces.application.ApplicationImpl.&lt;init&gt;(ApplicationImpl.java:214)
      at com.sun.faces.application.ApplicationFactoryImpl.getApplication(ApplicationFactoryImpl.java:107)
      ...
      Etc............ (lines 286 to 107 repeat over and over)
  </code></pre>
  
  <p>Some examples of things I've looked into already that haven't helped me yet:</p>
  
  <ul>
  <li><a href="http://weblogic.sys-con.com/node/43816" rel="nofollow noreferrer">http://weblogic.sys-con.com/node/43816</a></li>
  <li><a href="https://stackoverflow.com/questions/16570287/java-lang-stackoverflowerror-running-jsf-2-example-on-weblogic-12c">java.lang.StackOverflowError Running JSF 2 example on Weblogic 12c</a></li>
  <li><a href="https://community.oracle.com/thread/2539035" rel="nofollow noreferrer">https://community.oracle.com/thread/2539035</a></li>
  </ul>
  
  <p><strong>EDIT:</strong> I think I've traced the issue back to a setting in my weblogic.xml file: "persistent-store-type=replicated_if_clustered" (see below). Once I removed this setting I haven't been able to reproduce the error. It seems this application is not serializing very well between servers in my cluster. Internal WebLogic logs have shown a replication error on random classes in my application. Hope it helps somebody else. If my error doesn't reappear in the next couple of days of testing, I'll come back and mark this as solved.</p>
  
  <pre><code>&lt;?xml version = '1.0' encoding = 'windows-1252'?&gt;
      &lt;weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.5/weblogic-web-app.xsd"
      xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"&gt;
      &lt;jsp-descriptor&gt;
          &lt;precompile&gt;true&lt;/precompile&gt;
      &lt;/jsp-descriptor&gt;
      &lt;container-descriptor&gt;
          &lt;prefer-web-inf-classes&gt;true&lt;/prefer-web-inf-classes&gt;
      &lt;/container-descriptor&gt;
      &lt;session-descriptor&gt;
          &lt;cookie-secure&gt;true&lt;/cookie-secure&gt;
          &lt;cookie-http-only&gt;true&lt;/cookie-http-only&gt;        
          &lt;!--&lt;persistent-store-type&gt;replicated_if_clustered&lt;/persistent-store-type&gt;--&gt;
          &lt;url-rewriting-enabled&gt;false&lt;/url-rewriting-enabled&gt;
      &lt;/session-descriptor&gt; 
  &lt;/weblogic-web-app&gt;
  </code></pre>
  
  <p><strong>EDIT2:</strong> There also seems to be a library conflict. I wasn't sending my JSTL library and tag library with the project because it should have been on the server. When I changed my deployment to include this .jar (glassfish.jstl_1.0.0.0_1-2-2-0.jar) it also made a lot of my errors go away, so my application must not have always been finding the libraries I thought it was finding. </p>