1. Jetty
  2. JETTY-151

ArrayIndexOutOfBoundsException from JSP file which is printing/writing long lines


    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 6.0.1
    • Fix Version/s: 6.0.2, 6.1.0pre1
    • Component/s: None
    • Labels:
    • Environment:
      Linux, Java build 1.6.0-beta2-b82
    • Number of attachments :


      I'm getting these ArrayIndexOutOfBoundsExceptions from a legacy JSP I'm suddenly in charge of. It seems like the code is printing very long lines, and that isn't handled properly.

      (It might be worth pointing out that the writing/printing is actually performed inside an invoked java class on the supplied out (javax.servlet.jsp.JspWriter), and not from the actual jsp.)

      I don't quite get the "writeUnchecked()" method of ByteArrayOutputStream2, as the whole idea with the "write()" is to handle the "overflowing of the array" by increasing its size? If this was supposed to be handled by autoflushing, then I think that there is a discrepency between the size of JspWriterImpl's buffer (which is 8192 at the time), and the buf in ByteArrayOutputStream2, which is 3000.

      At the time of the AIOOB, ByteArrayOutputStream2's vars:
      buf's length: 3000
      count: 3001 (probably obviously!)

      and JspWriterImpl's has the following:
      autoFlush: true
      bufferSize: 8192
      cb's length: 8192
      nextChar: 335

      Sorry for not having a testcase yet, I wanted to send this before I left work today!
      (However I reckon that people with insight into this apparent optimization might spot the problem quickly?)

      java.lang.ArrayIndexOutOfBoundsException: 3000
      at org.mortbay.util.ByteArrayOutputStream2.writeUnchecked(
      at org.mortbay.jetty.HttpGenerator$OutputWriter.write(
      at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(
      at org.apache.jasper.runtime.JspWriterImpl.flush(
      at org.apache.jsp.TextQueryTestV3_005f01_jsp._jspService(org.apache.jsp.TextQueryTestV3_005f01_jsp:942)
      at org.apache.jasper.runtime.HttpJspBase.service(
      at javax.servlet.http.HttpServlet.service(
      at org.apache.jasper.servlet.JspServletWrapper.service(
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(
      at org.apache.jasper.servlet.JspServlet.service(
      at javax.servlet.http.HttpServlet.service(
      at org.mortbay.jetty.servlet.ServletHolder.handle(
      at org.mortbay.jetty.servlet.ServletHandler.handle(
      at org.mortbay.jetty.servlet.SessionHandler.handle(
      at org.mortbay.jetty.handler.ContextHandler.handle(
      at org.mortbay.jetty.handler.ContextHandlerCollection.handle(
      at org.mortbay.jetty.handler.HandlerCollection.handle(
      at org.mortbay.jetty.handler.HandlerWrapper.handle(
      at org.mortbay.jetty.Server.handle(
      at org.mortbay.jetty.HttpConnection.handleRequest(
      at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(
      at org.mortbay.jetty.HttpParser.parseNext(
      at org.mortbay.jetty.HttpParser.parseAvailable(
      at org.mortbay.jetty.HttpConnection.handle(
      at org.mortbay.thread.BoundedThreadPool$

        Issue Links


          No work has yet been logged on this issue.


            • Assignee:
              Greg Wilkins
              Endre Stølsvik


              • Created: