From: SourceForge.net <no...@so...> - 2006-06-09 06:30:45
|
Bugs item #1503333, was opened at 2006-06-09 16:30 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=107322&aid=1503333&group_id=7322 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Other Group: None Status: Open Resolution: None Priority: 5 Submitted By: Trudi Ersvaer (trudiersvaer) Assigned to: Nobody/Anonymous (nobody) Summary: ArrayIndexOutOfBoundsException error + suggested fix. Initial Comment: My environment... jetty-5.1.11RC0 Windows XP Java 1.4.2_09 I have created a custom handler for Jetty which proxies a request onto a different endpoint. My handler is the only one that is configured. After it runs "handled" is set to true. The proxy code is created with HTTPURLConnection. I am basically copying the request that the handler gets to the HTTPURLConnection's output stream (using org.mortbay.util.IO.copy()). I also copy the headers etc. When I get the response I do the opposite. The only other thing the handler does is add headers. A number of messages are sent before the error occurs. The error occurs during the copying of one of the responses from the proxied endpoint to Jetty's response. The stack I'm getting is... java.lang.ArrayIndexOutOfBoundsException at java.lang.System.arraycopy(Native Method) at org.mortbay.util.ByteBufferOutputStream.write (ByteBufferOutputStream.java:198) at org.mortbay.http.BufferedOutputStream.write (BufferedOutputStream.java:153) at org.mortbay.http.HttpOutputStream.write (HttpOutputStream.java:423) â¦My handler stack at org.mortbay.http.HttpContext.handle (HttpContext.java:1530) at org.mortbay.http.HttpContext.handle (HttpContext.java:1482) at org.mortbay.http.HttpServer.service (HttpServer.java:909) at org.mortbay.http.HttpConnection.service (HttpConnection.java:820) at org.mortbay.http.HttpConnection.handleNext (HttpConnection.java:986) at org.mortbay.http.HttpConnection.handle (HttpConnection.java:837) at org.mortbay.http.SocketListener.handleConnection (SocketListener.java:245) at org.mortbay.util.ThreadedServer.handle (ThreadedServer.java:357) at org.mortbay.util.ThreadPool$PoolThread.run (ThreadPool.java:534) It is quiet a complicated set of requests that I send to get the error to occur so I haven't included a test case. Instead, I think I know where the problem is (if need be, I can create a test case for you...but it is a bit of work). It looks like there might be a bug in BufferedOutputStream.resetStream(). The current code is: super.reset(_httpMessageWriter.capacity()); _commited=false; I think the call to the reset() method of ByteBufferedOutputStream is the problem. ByteBufferedOutputStream.reset is coded as: public void reset(int reserve) { _preReserve=reserve; _pos=_preReserve; _start=_preReserve; } I think the parameter is meant to be a new value of the preReserve. However, the value isn't checked perhaps a call to ensureReserve() should appear there?). In my case, the parameter being passed as over 9000, when the current buffer size was just over 8000. In BufferedOutputStream, I think the call to reset is being passed the current capacity of the message writer...rather than the desired reserve? I think the reset method of ByteBufferOutputStream could be removed altogether. It is only used in two places, and in both cases it would be equally easy to call the resetStream method instead. In summary, the recommended changes are: The BufferedOutputStream.resetStream() method code becomes: super.resetStream(); // replacing super.reset (_httpMessageWriter.capacity ()); _commited=false; while BufferedOutputStream.flush() finally clause becomes: finally { super.resetStream(); // replacing reset(_preReserve); } Attached is the file with my recommended changes. See lines 211 & 240. Thanks in advance. Trudi. Also, my server is started with the following configuration... <?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd" > <Configure class="org.mortbay.jetty.Server"> <Call name="addListener"> <Arg> <New class="org.mortbay.http.SocketListener"> <Set name="Port"><SystemProperty name="jetty.port" default="6666"/></Set> <Set name="Host">localhost</Set> <Set name="PoolName">P1</Set> <Set name="MinThreads">20</Set> <Set name="MaxThreads">200</Set> <Set name="lowResources">50</Set> <Set name="MaxIdleTimeMs">30000</Set> <Set name="LowResourcePersistTimeMs">2000</Set> <Set name="acceptQueueSize">0</Set> <Set name="ConfidentialPort">8443</Set> <Set name="IntegralPort">8443</Set> </New> </Arg> </Call> <Call name="addContext"> <Arg> <New class="org.mortbay.http.HttpContext"> <Set name="ContextPath">/</Set> </New> </Arg> <Call name="addHandler"> <Arg> <New class="com.myHandler"/> </Arg> </Call> </Call> </Configure> ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=107322&aid=1503333&group_id=7322 |