Search code examples
jspnullpointerexceptionwebsphereresponse

JSP output ends with NullPointerException after 680 KB


I have a legacy JSP that has scriplets, I am doing testing of it in our application on Websphere 7.0.0.13. The same JSP, with exact same data works correctly in Weblogic 10.3.2.

The JSP uses code to produce a lot of HTML output + javascript. On Websphere is failing consistently with a NullPointerException in the middle of the JSP's output. Everytime it fails it fails around 680 KB of data in the page.

If I view source from a browser, the last line of output gets cutoff, something like this

";document.getElementById( 'start.123.12345.67891.123123123' ).appendChild(divTag);exError 500: java.lang.NullPointerException

No other output. Logs report an uncaught NullPointerException from my JSP.

Most of this output is generated using the page's JspWriter out.println(); inside of scriptlets.

I have tried adding a page directive for autoflush=true thinking it may be a buffer issue but it still fails. <%@page autoFlush="true" %>


Solution

  • I resolved this after reviewing the generated java file using the keepgenerated JSP engine config parameter and using the line number from the stack trace of the NullPointerException.

    The original developer set the JspWriter out to null in a scriplet at the end of the file.

    <% 
      out = null;
    %>
    </html>
    

    In the Websphere generated .java file the out variable is set to null before something like this:

    out = null;
    out.write(_jsp_string55);
    

    If i comment out the out = null; statement in the JSP file, this resolves the issue.

    FYI - I've also created a test JSP that writes out far more than 680 KB by just looping and printing out to the JspWriter. I found that no matter the size of the output I could not reproduce the same NullPointerException.