10 Replies Latest reply on Mar 16, 2008 4:26 AM by fernando_jmt

    Query.getMaxResults not always checked for null result

    trentlarson

      There are many places where Query.getMaxResults is called but not checked for a null value.  This causes my app to crash, for example, when I used the ...List.xhtml view in seam-gen and EntityQuery.nextExists crashed with a NullPointerException on that max value test.


      I'm using 2.0.1.GA


      (BTW, this is my second submission; I got an error clicking on 'Help' in my first submission.  Erg.)

        • 1. Re: Query.getMaxResults not always checked for null result
          trentlarson

          Want me to submit this as a bug?  (There are places where a null has significance, so I expect you'll have to make this check everywhere.)

          • 2. Re: Query.getMaxResults not always checked for null result
            pmuir

            Ok, lets see the stack trace.

            • 3. Re: Query.getMaxResults not always checked for null result
              trentlarson

              I'll do that, but it's really not relevant because there are many places org/jboss/seam/framework sources that reference 'getMaxResults' without checking for null, and they should all be fixed.


              Here 'tis:


              Caused by: java.lang.NullPointerException
                      at org.jboss.seam.framework.EntityQuery.isNextExists(EntityQuery.java:47)
                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                      at java.lang.reflect.Method.invoke(Method.java:585)
                      at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
                      at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                      at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                      at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
                      at org.jboss.seam.util.Work.workInTransaction(Work.java:40)
                      at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                      at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                      at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                      at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
                      at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
                      at com.icentris.moneplanner.admin.session.ClientList_$$_javassist_2.isNextExists(ClientList_$$_javassist_2.java)
                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                      at java.lang.reflect.Method.invoke(Method.java:585)
                      at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
                      at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
                      at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
                      at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
                      at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
                      at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                      at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
                      ... 47 more

              • 4. Re: Query.getMaxResults not always checked for null result
                pmuir

                Please enclose the stack trace in back ticks (`stack trace`) and make sure to include the root cause.


                And yes, it is relevant - I'm not in the habit of making random changes to Seam source on the advice of people from a public forum without understanding their issue first. And I happen to think this is a good thing.


                And in this case, the bug is yours. You can't call methods like isNextExists() on a query where you haven't set the maxResults() (it doesn't make any sense if you think carefully).


                But we could have a better error message explaining this. So please put an issue for the error message in JIRA.

                • 5. Re: Query.getMaxResults not always checked for null result
                  trentlarson

                  A little more background may help: I started with a HSQL DB with 2 tables (Client and Partner), then ran seam-gen to set up my project and I have not manually changed any code.  I started Jboss and went to my app, then clicked on ClientView on the top and got the error.  So the origin of the problem may actually be in the seam-gen piece, such as the 'new-project' task.


                  Good luck.  I'll add a JIRA task now for the error message; let me know if you want another one for this new-project problem.


                  07:50:27,570 ERROR [STDERR] Mar 14, 2008 7:50:27 AM com.sun.facelets.FaceletViewHandler handleRenderException
                  SEVERE: Error Rendering View[/ClientList.xhtml]
                  javax.faces.FacesException: javax.el.ELException: /ClientList.xhtml @347,33 rendered="#{clientList.nextExists}": Error reading 'nextExists' on type com.icentris.moneplanner.admin.session.ClientList_$$_javassist_2
                          at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:373)
                          at javax.faces.component.UIComponent.encodeAll(UIComponent.java:880)
                          at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
                          at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                          at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
                          at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
                          at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
                          at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
                          at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
                          at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
                          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                          at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                          at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                          at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                          at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                          at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
                          at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
                          at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                          at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                          at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                          at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                          at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                          at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                          at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                          at java.lang.Thread.run(Thread.java:595)
                  Caused by: javax.el.ELException: /ClientList.xhtml @347,33 rendered="#{clientList.nextExists}": Error reading 'nextExists' on type com.icentris.moneplanner.admin.session.ClientList_$$_javassist_2
                          at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
                          at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:370)
                          ... 46 more
                  Caused by: java.lang.NullPointerException
                          at org.jboss.seam.framework.EntityQuery.isNextExists(EntityQuery.java:47)
                          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                          at java.lang.reflect.Method.invoke(Method.java:585)
                          at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
                          at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
                          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                          at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
                          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                          at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
                          at org.jboss.seam.util.Work.workInTransaction(Work.java:40)
                          at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
                          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                          at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
                          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                          at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                          at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
                          at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
                          at com.icentris.moneplanner.admin.session.ClientList_$$_javassist_2.isNextExists(ClientList_$$_javassist_2.java)
                          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                          at java.lang.reflect.Method.invoke(Method.java:585)
                          at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
                          at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
                          at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
                          at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
                          at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
                          at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                          at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
                          ... 47 more
                  

                  • 6. Re: Query.getMaxResults not always checked for null result
                    trentlarson

                    <tail between my legs>




                    Well, nevermind: I just ran through the whole sequence again and this time it worked.  I'll keep my eyes open for this same thing, and I'll give the full story next time.


                    Thanks forcing me to continue!  And sorry for the distraction.



                    </tail...>


                    • 7. Re: Query.getMaxResults not always checked for null result
                      trentlarson

                      Aha!  I found the situation: in the generated ...List.java code, it implements the getMaxResults method; however, when this is implemented, Hibernate includes a top ? in my select statements for the FrontBase driver which breaks the driver.  Ug.  To work around this, I removed the getMaxResults implementation, and then Hibernate creates SQL that doesn't break when talking to the DB.  But it appears that causes other problems.


                      So I did change some code from the generated templates.  I now have to find a way to stop Hibernate from generating that code and still make sure other code doesn't break.


                      BTW, I must disagree that isNextExists should throw errors if there is no maxResults set; I expect my DAO layer should be able to show me everything even if that's not set.  The EntityQuery.createQuery method and the Query.getPageCount methods handle this situation, so I don't see why isNextExists should break.  At very least, let's document that dependency; I'll put that suggestion in the JIRA task.


                      (Oh, and BTW, kudos to the Seam for making it so easy to get up and running with an entire application.  That's sweet.)


                      Cheers!

                      • 8. Re: Query.getMaxResults not always checked for null result
                        pmuir

                        I think that a better exception would be the best thing.

                        • 9. Re: Query.getMaxResults not always checked for null result
                          wiggy

                          hit the same problem -


                          i fixed it by copying the EntityQuery into my own space and correcting the errors i saw - did this for next/last previous functions


                          see


                          http://www.seamframework.org/Community/SeamFrameworkEntityQueryBug


                          i just posted - this may help you get past the initial problem until a 'well designed' fix is put in place.


                          I have this working on my form now.  Didnt trawl through all the cases yest so probably more errors to come out .


                          • 10. Re: Query.getMaxResults not always checked for null result
                            fernando_jmt