2 Replies Latest reply on Dec 11, 2008 10:13 PM by Francisco Jose Peredo Noguez

    NPE in parameter conversion: String to Long

    Francisco Jose Peredo Noguez Master

      I am getting this WARNING in my logs:


      WARN  org.jboss.seam.navigation.Param - could not create converter for: categoriaBienCveCategoria
      java.lang.NullPointerException
           at org.jboss.seam.jsf.SeamApplication$ConverterLocator.locateConverter(SeamApplication.java:166) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.jsf.SeamApplication$ConverterLocator.getConverter(SeamApplication.java:148) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.jsf.SeamApplication.createConverter(SeamApplication.java:122) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.navigation.Param.getConverter(Param.java:66) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.navigation.Param.getStringValueFromModel(Param.java:143) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.navigation.RedirectNavigationHandler.navigate(RedirectNavigationHandler.java:46) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.navigation.Rule.execute(Rule.java:100) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.navigation.Navigation.navigate(Navigation.java:58) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.navigation.Pages.navigate(Pages.java:206) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.jsf.SeamNavigationHandler.handleNavigation(SeamNavigationHandler.java:42) [jboss-seam.jar:2.1.0.SP1]
           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:130) [jsf-impl.jar:1.2_09-b01-BETA1]
           at javax.faces.component.UICommand.broadcast(UICommand.java:387) [jsf-api.jar:1.2_09-b01-BETA1]
           at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55) [richfaces-impl.jar:3.2.2.GA]
           at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321) [richfaces-impl.jar:3.2.2.GA]
           at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296) [richfaces-impl.jar:3.2.2.GA]
           at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253) [richfaces-impl.jar:3.2.2.GA]
           at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:467) [richfaces-impl.jar:3.2.2.GA]
           at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82) [jsf-impl.jar:1.2_09-b01-BETA1]
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) [jsf-impl.jar:1.2_09-b01-BETA1]
           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl.jar:1.2_09-b01-BETA1]
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265) [jsf-api.jar:1.2_09-b01-BETA1]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) [catalina.jar:na]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na]
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:52) [jboss-seam-debug.jar:2.1.0.SP1]
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.web.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:43) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:39) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:46) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.1.0.SP1]
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177) [richfaces-impl.jar:3.2.2.GA]
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:279) [richfaces-impl.jar:3.2.2.GA]
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380) [richfaces-impl.jar:3.2.2.GA]
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507) [richfaces-impl.jar:3.2.2.GA]
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.1.0.SP1]
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:159) [jboss-seam.jar:2.1.0.SP1]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:na]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na]
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina.jar:na]
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [catalina.jar:na]
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:434) [catalina.jar:na]
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) [catalina.jar:na]
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [catalina.jar:na]
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:111) [catalina.jar:na]
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) [catalina.jar:na]
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) [tomcat-coyote.jar:na]
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584) [tomcat-coyote.jar:na]
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) [tomcat-coyote.jar:na]
           at java.lang.Thread.run(Thread.java:595) [na:na]
      



      when I hit this navigation rule:


      <rule if-outcome="persisted" if="#{not empty categoriaBienCveCategoriaFor}">
                   <end-conversation/>
                   <redirect view-id="#{categoriaBienFrom}">
                        <param name="categoriaBienCveCategoria" value="#{categoriaBienCveCategoriaFor}"/>
                        <param name="categoriaBienFrom" value="/Crud/CategoriaBien/CategoriaBienList.xhtml"/>                  
                   </redirect>
                </rule>
      



      As a side effect the categoriaBienCveCategoria is not set with the value in #{categoriaBienCveCategoriaFor}, and that makes my validation rule useless.


      But I found a weird workaround:



      <rule if-outcome="persisted" if="#{not empty categoriaBienCveCategoriaFor}">
                   <end-conversation/>
                   <redirect view-id="#{categoriaBienFrom}">
                        <param name="categoriaBienCveCategoria" value="#{categoriaBienCveCategoriaFor+0}"/>
                        <param name="categoriaBienFrom" value="/Crud/CategoriaBien/CategoriaBienList.xhtml"/>                  
                   </redirect>
                </rule>
      



      Did you notice the +0 in #{categoriaBienCveCategoriaFor+0} ? That seems to be triggering the right conversion to match the setter for Long categoriaBienCveCategoria;


      I think this is a bug in the way Seam 2.1.0SP1 is dealing with conversions.


      Anyone else has this problem?




        • 2. Re: NPE in parameter conversion: String to Long
          Francisco Jose Peredo Noguez Master

          Mmmm, the root of this problem seems to be in org.jboss.seam.navigation.Param
          in the method getConverter():


           public Converter getConverter()
             {
                if (converterId!=null)
                {
                   return FacesContext.getCurrentInstance().getApplication().createConverter(converterId);
                }
                else if (converterValueExpression!=null)
                {
                   return (Converter) converterValueExpression.getValue();
                }
                else if (valueExpression==null)
                {
                   return null;
                }
                else
                {
                   Class<?> type = valueExpression.getType(); //<--THIS RETURNS NULL
                   return FacesContext.getCurrentInstance().getApplication().createConverter(type);           
                }
             }
          



          The problem is that Class<?> type = valueExpression.getType(); return null for the value expression: #{categoriaBienCveCategoriaFor}, but I am not sure why... well, the thing is that then the ConverterLocator does not know what to do...


          I have the feeling it is problem similar to JBSEAM-3430, basically the valueExpression does not know its own type.


          The thing that disturbs me a little is that if we up in the stacktrace, we can see that in Param.getStringValueFromModel there is a catch that looks like this:


                   try
                   {
                      converter = getConverter();
                   }
                   catch (RuntimeException re)
                   {
                      //YUCK! due to bad JSF/MyFaces error handling
                      log.warn("could not create converter for: " + name, re);
                      return null;
                   }
          



          So... is this an expected crash? or this catch (RuntimeException re) is there to deal with other stuff and is only accidentally making it harder to me to realize what was going on (application didn't crash, it just didn't do what I wanted)?