You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Kin-Man Chung <Ki...@Eng.Sun.COM> on 2003/10/08 21:03:46 UTC

[5] IndexOutOfBoundsException from CharChunk

I am getting a sporadic IndexOutOfBoundsException and it seems to come from
org.apache.tomcat.util.buf.CharChunk.flushBuffer.  The trace is

Servlet.service() for servlet jsp threw exception
java.lang.IndexOutOfBoundsException
        at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:132)
        at java.io.OutputStreamWriter.write(OutputStreamWriter.java:191)
        at org.apache.tomcat.util.buf.WriteConvertor.write(C2BConverter.java:228
)
        at org.apache.tomcat.util.buf.C2BConverter.convert(C2BConverter.java:120
)
        at org.apache.coyote.tomcat5.OutputBuffer.realWriteChars(OutputBuffer.ja
va:606)
        at org.apache.tomcat.util.buf.CharChunk.flushBuffer(CharChunk.java:463)
        at org.apache.coyote.tomcat5.OutputBuffer.flush(OutputBuffer.java:357)
        at org.apache.coyote.tomcat5.CoyoteWriter.flush(CoyoteWriter.java:117)
        at org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:203)
        at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary
.java:990)
...

In CharChunk, 

    public void flushBuffer()
        throws IOException
    {
        //assert out!=null
        if( out==null ) {
            throw new IOException( "Buffer overflow, no sink " + limit + " " +
                                   buff.length  );
        }
        out.realWriteChars( buff, start, end - start );
        end=start;
    }

when realWriteChars is called, the value for start is 0, end is 16384, and
buff.length is 8192, hence the exception.

Does anyone knows how end can go beyond 8192?  This only hapeens very
rarely, under heavy load.

-Kin-man





---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Re: [5] IndexOutOfBoundsException from CharChunk

Posted by Remy Maucherat <re...@apache.org>.
Kin-Man Chung wrote:

> I am getting a sporadic IndexOutOfBoundsException and it seems to come from
> org.apache.tomcat.util.buf.CharChunk.flushBuffer.  The trace is
> 
> Servlet.service() for servlet jsp threw exception
> java.lang.IndexOutOfBoundsException
>         at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:132)
>         at java.io.OutputStreamWriter.write(OutputStreamWriter.java:191)
>         at org.apache.tomcat.util.buf.WriteConvertor.write(C2BConverter.java:228
> )
>         at org.apache.tomcat.util.buf.C2BConverter.convert(C2BConverter.java:120
> )
>         at org.apache.coyote.tomcat5.OutputBuffer.realWriteChars(OutputBuffer.ja
> va:606)
>         at org.apache.tomcat.util.buf.CharChunk.flushBuffer(CharChunk.java:463)
>         at org.apache.coyote.tomcat5.OutputBuffer.flush(OutputBuffer.java:357)
>         at org.apache.coyote.tomcat5.CoyoteWriter.flush(CoyoteWriter.java:117)
>         at org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:203)
>         at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary
> .java:990)
> ...
> 
> In CharChunk, 
> 
>     public void flushBuffer()
>         throws IOException
>     {
>         //assert out!=null
>         if( out==null ) {
>             throw new IOException( "Buffer overflow, no sink " + limit + " " +
>                                    buff.length  );
>         }
>         out.realWriteChars( buff, start, end - start );
>         end=start;
>     }
> 
> when realWriteChars is called, the value for start is 0, end is 16384, and
> buff.length is 8192, hence the exception.
> 
> Does anyone knows how end can go beyond 8192?  This only hapeens very
> rarely, under heavy load.

I don't know. I suppose limit is 8192 also. Are you sure your test is 
clean, and without anything weird ? (somehow, I doubt it)
I've changed a bit the algorithm in ByteChunk, and it seems better, but 
the CharChunk algorithm is identical in 4.1's ByteChunk and CharChunk. 
We would have noticed anything bad, I think.

Remy



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org