You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Animesh Chaturvedi - US <an...@allegronetworks.com> on 2001/04/19 02:48:17 UTC

Bug in tomcat3.2.1 RecycleBufferedInputStream class - or solution to ContextManager: error reading request:ArrayIndexOutOfBoundsException

Hi 

Tomcct 3.2.1 does not work with Kaffe JVM. When a request is sent to Tomcat 

you get following error

ContextManager: Error reading request, ignored -
java.lang.ArrayIndexOutOfBoundsException 
        at java.lang.System.arraycopy(System.java:native) 
        at java.io.BufferedInputStream.read(BufferedInputStream.java:118) 
        at java.io.BufferedInputStream.read(BufferedInputStream.java:69) 
        at
org.apache.tomcat.service.http.HttpRequestAdapter.doRead(HttpRequestAdapter.
java:115) 
        at
org.apache.tomcat.core.BufferedServletInputStream.doRead(BufferedServletInpu
tStream.java:106) 
        at
org.apache.tomcat.core.BufferedServletInputStream.read(BufferedServletInputS
tream.java:128) 
        at
javax.servlet.ServletInputStream.readLine(ServletInputStream.java:138) 
        at
org.apache.tomcat.service.http.HttpRequestAdapter.readNextRequest(HttpReques
tAdapter.java:129) 
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:195) 
        at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416) 
        at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498) 
        at java.lang.Thread.run(Thread.java:325) 


After lot of debugging I found that there is bug with
RecycleBufferedInputStream. 
The original RecycleBufferedInputStream class only resets count = 0.
This results sometimes in count to be set to zero and pos is not changed so
it is now greater than count. and 
when yo do a System.arraycopy with length = count -pos. It gets a negative
value hence the array index out of bounds exception. 

So you have to change the two functions in RecycleBufferedInputStream like
this.

    public void setInputStream( InputStream is ) {
this.in = is;
this.pos = this.count = 0;
this.markpos = -1;
    }

    public void recycle() {
this.in = null;
this.pos = this.count = 0;
this.markpos = -1;
    }


Now tomcat 3.2.1 works fine with Kaffe VM.


Animesh