1 Reply Latest reply on Sep 22, 2012 5:41 PM by Patrick Garner

    NPE in BehaviorsTagHandlerDelegateFactoryImpl when processing <h:head>

    Patrick Garner Newbie

      After making changes in the codebase (very few in the facelets), the following exception results when a request is made.  I haven't made any changes to faces-config.xml or web.xml.  I upgraded richfaces from 4.0.0.Final to v. 4.3.0.20120802-M1 prior to this last round of work, and downgrading back to 4.0.0.Final does not resolve the problem.  I'm using AS 7.1.1.Final-SNAPSHOT.  There are no warnings or errors in server.log during startup.

       

       

      16:43:39,887 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/Patrac].[Faces Servlet]] (http--127.0.0.1-8443-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.NullPointerException
          at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
          at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
          at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
          at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:308) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:367) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:346) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:155) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:774) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.7-jbossorg-2.jar:]
          at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
          at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
          at com.patrac.filter.NoCacheFilter.doFilter(NoCacheFilter.java:46) [classes:]
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489) [jbossweb-7.0.13.Final.jar:]
          at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
          at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
          at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:897) [jbossweb-7.0.13.Final.jar:]
          at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:626) [jbossweb-7.0.13.Final.jar:]
          at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2039) [jbossweb-7.0.13.Final.jar:]
          at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_03]
      

       

       

      com.sun.faces.facelets.tag.jsf.htm.HtmlComponentHandler (descendent of DelegatingMetaTagHandler), upon which apply() is invoked, is where the NPE is thrown:

       

       

      public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
                getTagHandlerDelegate().apply(ctx, parent);
           }
       
      

       

      When apply is invoked parent's state is as follows:

       

      • parent = {javax.faces.component.UIViewRoot@12399}
      • skipPhase = false
      • beforeMethodException = false
      • phaseListenerIterator = null
      • events = null
      • viewScope = null
      • viewListeners = null
      • values = null
      • pdMap = {java.util.HashMap@12400} size = 29
      • listenersByEventClass = null
      • attributes = {javax.faces.component.UIComponentBase$AttributesMap@12401} size = 1
        • [0] = {java.util.HashMap$Entry@12529}"com.sun.faces.facelets.MARK_DELETED" -> "true"
      • clientId = null
      • id = {java.lang.String@12521}"j_id1"
      • parent = null
      • children = {javax.faces.component.UIComponentBase$ChildrenList@12522} size = 3
        • [0] = {com.sun.faces.facelets.compiler.UIInstructions@12652}"\n"
        • [1] = {com.sun.faces.facelets.compiler.UIInstructions@12653}"\n\n"
        • [2] = {com.sun.faces.facelets.compiler.UIInstructions@12654}"\n    "
      • facets = {javax.faces.component.UIComponentBase$FacetsMap@12523} size = 1
        • [0] = {javax.faces.component.UIComponentBase$FacetsMapEntrySetEntry@12660}"javax_faces_location_HEAD" -> {com.sun.faces.component.ComponentResourceContainer@12662}
      • listeners = null
      • transientFlag = false
      • behaviors = null
      • attributesThatAreSet = null
      • stateHelper = {javax.faces.component.ComponentStateHelper@12524}
        • component = {javax.faces.component.UIViewRoot@12399}
        • isTransient = false
        • deltaMap = {java.util.HashMap@12663} size = 0
        • defaultMap = {java.util.HashMap@12664} size = 7
          • [0] = {java.util.HashMap$Entry@12667}"lastId" -> "1"
          • [1] = {java.util.HashMap$Entry@12670}"attributesThatAreSet" ->  size = 1
          • [2] = {java.util.HashMap$Entry@12673}"attributes" ->  size = 1
          • [3] = {java.util.HashMap$Entry@12676}"locale" -> "en"
          • [4] = {java.util.HashMap$Entry@12679}"rendererType" -> null
          • [5] = {java.util.HashMap$Entry@12681}"renderKitId" -> "HTML_BASIC"
          • [6] = {java.util.HashMap$Entry@12684}"viewId" -> "/index.xhtml"
        • transientState = null
      • compositeParent = null
      • bindings = null
      • initialState = false
      • isInView = false
      • resourceBundleMap = null
      • isUIComponentBase = false
      • isUIComponentBaseIsSet = false
      • _isPushedAsCurrentRefCount = 0
      • isCompositeComponent = {java.lang.Boolean@12525}"false"

       

       

      The problem is that getTagHandlerDelegate() returns null because delegateFactory.createComponentHandlerDelegate returns null.

       


      protected TagHandlerDelegate getTagHandlerDelegate() {

      if (null == helper) {

      helper = delegateFactory.createComponentHandlerDelegate(this);

      }

      return helper;

      }

       

       

      delegateFactory is an instance of org.richfaces.view.facelets.html.BehaviorsTagHandlerDelegateFactoryImpl, whose createComponentHandlerDelegate method looks like this:

       


      public TagHandlerDelegate createComponentHandlerDelegate(ComponentHandler owner) {

      if (owner instanceof BehaviorsAddingComponentHandlerWrapper) {

      // this is to avoid StackOverflowError because of ComponentHandler constructor call

      return null;

      }

      ComponentHandler wrappedHandler = new BehaviorsAddingComponentHandlerWrapper(owner);

      return factory.createComponentHandlerDelegate(wrappedHandler);

      }

       

      factory is also an instance of BehaviorsTagHandlerDelegateFactoryImpl so createComponentHandlerDelegate is recursively invoked a second time, and because owner is an instance of BehaviorsAddingComponentHandlerWrapper the second time around, returns null.

       

      when createComponentHandlerDelegate is invoked the first time, owner's state is as follows

       

      • owner = {com.sun.faces.facelets.tag.jsf.html.HtmlComponentHandler@11136}"/WEB-INF/screens/public/masterLayout.xhtml @12,13 "
      • helper = null
      • componentConfig = {com.sun.faces.facelets.tag.AbstractTagLibrary$ComponentConfigWrapper@12703}
        • parent = {com.sun.faces.facelets.compiler.TagUnit@12758}"/WEB-INF/screens/public/masterLayout.xhtml @12,13 "
        • componentType = {java.lang.String@12759}"javax.faces.Output"
        • rendererType = {java.lang.String@12760}"javax.faces.Head"
      • binding = null
      • disabled = null
      • delegateFactory = {org.richfaces.view.facelets.html.BehaviorsTagHandlerDelegateFactoryImpl@12359}
        • factory = {org.richfaces.view.facelets.html.BehaviorsTagHandlerDelegateFactoryImpl@12361}
      • lastType = {java.lang.Class@11156}"class java.lang.Object"
        • cachedConstructor = null
        • newInstanceCallerCache = null
        • name = {java.lang.String@12730}"java.lang.Object"
        • declaredFields = {java.lang.ref.SoftReference@12731}
        • publicFields = null
        • declaredMethods = {java.lang.ref.SoftReference@12732}
        • publicMethods = {java.lang.ref.SoftReference@12733}
        • declaredConstructors = {java.lang.ref.SoftReference@12734}
        • publicConstructors = null
        • declaredPublicFields = {java.lang.ref.SoftReference@12735}
        • declaredPublicMethods = {java.lang.ref.SoftReference@12736}
        • classRedefinedCount = 0
        • lastRedefinedCount = 0
        • genericInfo = null
        • enumConstants = null
        • enumConstantDirectory = null
        • annotations = {java.util.Collections$EmptyMap@12737} size = 0
        • declaredAnnotations = {java.util.Collections$EmptyMap@12737} size = 0
        • annotationType = null
      • mapper = null
      • tagId = {java.lang.String@12704}"1683f8d3"
      • tag = {javax.faces.view.facelets.Tag@12705}"/WEB-INF/screens/public/masterLayout.xhtml @12,13 "
        • attributes = {com.sun.faces.facelets.tag.TagAttributesImpl@12722}""
        • location = {javax.faces.view.Location@12723}"/WEB-INF/screens/public/masterLayout.xhtml @12,13"
        • namespace = {java.lang.String@12724}"http://java.sun.com/jsf/html"
        • localName = {java.lang.String@12725}"head"
        • qName = {java.lang.String@12726}"h:head"
      • nextHandler = {javax.faces.view.facelets.CompositeFaceletHandler@12706}
        • children = {javax.faces.view.facelets.FaceletHandler[6]@12709}
          • [0] = {com.sun.faces.facelets.compiler.UIInstructionHandler@12710}"\n        \n        \n        "
          • [3] = {com.sun.faces.facelets.tag.ui.InsertHandler@12713}"/WEB-INF/screens/public/masterLayout.xhtml @15,44 "
          • [4] = {com.sun.faces.facelets.tag.jsf.html.ScriptResourceHandler@12714}"/WEB-INF/screens/public/masterLayout.xhtml @16,73 "
          • [5] = {com.sun.faces.facelets.compiler.UIInstructionHandler@12715}"\n       

       

      and at the second invocation owner's state doesn't appear to change e.g.:

       

      • owner = {com.sun.faces.facelets.tag.jsf.html.HtmlComponentHandler@11136}"/WEB-INF/screens/public/masterLayout.xhtml @12,13 "
      • helper = null
      • componentConfig = {com.sun.faces.facelets.tag.AbstractTagLibrary$ComponentConfigWrapper@12703}
        • parent = {com.sun.faces.facelets.compiler.TagUnit@12758}"/WEB-INF/screens/public/masterLayout.xhtml @12,13 "
        • componentType = {java.lang.String@12759}"javax.faces.Output"
        • rendererType = {java.lang.String@12760}"javax.faces.Head"
      • binding = null
      • disabled = null
      • delegateFactory = {org.richfaces.view.facelets.html.BehaviorsTagHandlerDelegateFactoryImpl@12359}
        • factory = {org.richfaces.view.facelets.html.BehaviorsTagHandlerDelegateFactoryImpl@12361}
      • lastType = {java.lang.Class@11156}"class java.lang.Object"
        • cachedConstructor = null
        • newInstanceCallerCache = null
        • name = {java.lang.String@12730}"java.lang.Object"
        • declaredFields = {java.lang.ref.SoftReference@12731}
        • publicFields = null
        • declaredMethods = {java.lang.ref.SoftReference@12732}
        • publicMethods = {java.lang.ref.SoftReference@12733}
        • declaredConstructors = {java.lang.ref.SoftReference@12734}
        • publicConstructors = null
        • declaredPublicFields = {java.lang.ref.SoftReference@12735}
        • declaredPublicMethods = {java.lang.ref.SoftReference@12736}
        • classRedefinedCount = 0
        • lastRedefinedCount = 0
        • genericInfo = null
        • enumConstants = null
        • enumConstantDirectory = null
        • annotations = {java.util.Collections$EmptyMap@12737} size = 0
        • declaredAnnotations = {java.util.Collections$EmptyMap@12737} size = 0
        • annotationType = null
      • mapper = null
      • tagId = {java.lang.String@12704}"1683f8d3"
      • tag = {javax.faces.view.facelets.Tag@12705}"/WEB-INF/screens/public/masterLayout.xhtml @12,13 "
        • attributes = {com.sun.faces.facelets.tag.TagAttributesImpl@12722}""
        • location = {javax.faces.view.Location@12723}"/WEB-INF/screens/public/masterLayout.xhtml @12,13"
        • namespace = {java.lang.String@12724}"http://java.sun.com/jsf/html"
        • localName = {java.lang.String@12725}"head"
        • qName = {java.lang.String@12726}"h:head"
      • nextHandler = {javax.faces.view.facelets.CompositeFaceletHandler@12706}
        • children = {javax.faces.view.facelets.FaceletHandler[6]@12709}
          • [0] = {com.sun.faces.facelets.compiler.UIInstructionHandler@12710}"\n        \n        \n        "
          • [3] = {com.sun.faces.facelets.tag.ui.InsertHandler@12713}"/WEB-INF/screens/public/masterLayout.xhtml @15,44 "
          • [4] = {com.sun.faces.facelets.tag.jsf.html.ScriptResourceHandler@12714}"/WEB-INF/screens/public/masterLayout.xhtml @16,73 "
          • [5] = {com.sun.faces.facelets.compiler.UIInstructionHandler@12715}"\n       

       

      This has me stumped, especially because createComponentHandlerDelegate is being invoked recursively as a result of factory being an instance of  BehaviorsAddingComponentHandlerWrapper.  Any ideas on where I should go from here?