6 Replies Latest reply on May 16, 2013 8:28 AM by sfcoy

    JSTL NullPointerException

    martsecurit

      Hello.

       

      I have a war that runs without fault under Tomcat. When I deploy to JBoss I get this error from my custon JSTL tags:

       

       

      {code}

      15:44:18,275 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/tbadmin].[jsp]] (http--127.0.0.1-8080-9) Servlet.service() for servlet jsp threw exception: java.lang.NullPointerException

          at org.apache.jasper.runtime.BodyContentImpl.clear(BodyContentImpl.java:251) [jbossweb-7.0.13.Final.jar:]

          at javax.servlet.jsp.tagext.BodyContent.clearBody(BodyContent.java:126) [jboss-jsp-api_2.2_spec-1.0.0.Final.jar:1.0.0.Final]

          at org.apache.jasper.runtime.BodyContentImpl.setWriter(BodyContentImpl.java:307) [jbossweb-7.0.13.Final.jar:]

          at org.apache.jasper.runtime.PageContextImpl.pushBody(PageContextImpl.java:728) [jbossweb-7.0.13.Final.jar:]

          at org.apache.jasper.runtime.PageContextImpl.pushBody(PageContextImpl.java:714) [jbossweb-7.0.13.Final.jar:]

          at org.apache.jsp.workflow_002dconsole_jsp._jspx_meth_tbag_005faclButton_005f0(workflow_002dconsole_jsp.java:7018)

          at org.apache.jsp.workflow_002dconsole_jsp._jspService(workflow_002dconsole_jsp.java:1906)

          at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb-7.0.13.Final.jar:]

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

          at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:]

          at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:]

          at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb-7.0.13.Final.jar:]

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

      {code}

       

      This is the definition of the tag:


      <tag>

      <name>aclButton</name>

      <tag-class>my.package.jstl.AclButtonTag</tag-class>

      <body-content>JSP</body-content>

      <attribute>

      <name>accessType</name>

      <required>true</required>

      <description>Provide the AccessTypes for this ACL</description>

      <rtexprvalue>true</rtexprvalue>

      </attribute>

       

      Is there anything special I need to do when deploying on JBoss.

      This is a WAR that is being deployed and it deploys successfully.

       

      Thanks for reading

       

       

       

        • 1. Re: JSTL NullPointerException
          martsecurit

          Could it be anything to do with the fact that JBoss supplies it's own JSTL jars found here:

           

          jboss-7.1.1\modules\javax\servlet\jstl\api\main\jboss-jstl-api_1.2_spec-1.0.2.Final.jar

           

          If it is is there a way I can use the Sun ones? Or should I just add them to my WAR lib?

          • 2. Re: JSTL NullPointerException
            sfcoy

            This jar only contains the API classes, not the implementation. If you look at the stacktrace you can see that these classes are straight out of Tomcat.

             

            Does your WAR file contain any version of jstl in it, such as standard*.jar and/or jstl*.jar? If so, try removing them as they will be colliding with those provided by JBossAS (as it's required to do by the specs).

            1 of 1 people found this helpful
            • 3. Re: JSTL NullPointerException
              martsecurit

              Hello Stephen thank you for the response.

               

              No there are no servlet or jstl jars. When we deploy on Tomcat we install these into Tomcat as the are not supplied there.

              When we deploy on Websphere we do not need to provide them so they are not packaged their either. That way our packages are the same for both servers.

               

              Do I need to do something special for JBoss?  In the deployment descriptor or jboss deployment descriptor?

              Or could it be a memory issue with JSTL on JBoss (some googling brought old issues up like that)?

               

              This is a link to the memory issue is this still apparent in JBoss 7?

               

              https://issues.jboss.org/browse/ASPATCH-453

              • 4. Re: JSTL NullPointerException
                sfcoy

                I don't think ASPATCH-453 is related to your problem.

                 

                Something is calling javax.servlet.jsp.JspWriter#close() which is setting an internal buffer to null. A subsequent operation is then resulting in an NPE.

                • 5. Re: JSTL NullPointerException
                  martsecurit

                  Hello Stephen. Thanks for the reply

                   

                  Yeah I got that from the stack trace and that is the first thing I changed. I am calling a close on BodyContent in a finally block so I commented that out but it made no difference.

                  These are tags that function perfectly on Tomcat and WebSphere which leads to an issue to JBoss deployment or implementation of JSTL in my eyes.

                   

                  Anything else to check?

                   

                  This is the code you can see there is nothing unusual or exceptional.

                   

                  Do I need to close the JspWriter individually?

                   

                  cheers

                  Martin

                   

                   

                       public int doAfterBody() throws JspException{
                            BodyContent bodyContent = null;
                            try{
                                      bodyContent = getBodyContent();
                                      String body = bodyContent.getString();
                                      JspWriter out = bodyContent.getEnclosingWriter();
                                      if(jstlUtils.hasAccess(this.accessType, this.session, this.permission, this.environment)){
                                          out.print(body);
                                      }
                                      else{
                                          if(this.icon != null && this.label != null){
                                                  StringBuilder sb = new StringBuilder(64);
                                                  sb.append("")
                                                  .append("")
                                                  .append(this.icon)
                                                  .append("")
                                                  .append("").append(this.label).append("
                  ");
                                                  out.print(sb.toString());
                                          }
                                      }
                            }catch(Exception e){
                                 throw new JspException(e);
                            }finally{
                  //                    if(bodyContent != null){
                  //                        try { bodyContent.close(); } catch (IOException e) {}
                  //                    }
                            }
                            return SKIP_BODY;
                            
                       }
                  • 6. Re: JSTL NullPointerException
                    sfcoy

                    I found it surprising that you were closing the BodyContent. Checking the javadoc for javax.servlet.jsp.JspWriter#close() reveals that it is not necessary.

                     

                    Are you still getting exactly the same stack trace?

                     

                    Do you have other custom tags doing something similar?