DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7845>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7845

org.apache.avalon.excalibur.collections.VariableSizeBuffer loses data on resize





------- Additional Comments From [EMAIL PROTECTED]  2002-04-08 16:30 -------
This is how the add() method looks like now:


    public final void add( final Object o )
    {
        if( size() + 1 >= m_buffer.length )
        {
            Object[] tmp = new Object[ ( (m_buffer.length - 1) * 2) + 1 ];

            int copyPos = m_head;
            for (int i = 0; i < m_buffer.length; i++, copyPos = (copyPos + 1) 
% m_buffer.length)
            {
                tmp[ i ] = m_buffer[copyPos];
                m_buffer[ copyPos ] = null;
            }
            m_head = 0;
            m_tail = m_buffer.length - 1;

            m_buffer = tmp;
        }

        m_buffer[ m_tail ] = o;
        m_tail++;
        if (m_tail >= m_buffer.length)
        {
            m_tail = 0;
        }
    }


Basically what I changed is the way the buffer is resized. It rewinds and so 
keeping the semantics of a circular buffer.

About tests: it is easy to write one. I have one for using the db pooling part 
which uses this class then. How you see this is to do let's say inserts of 2 
elements followed by a remove of an element. Do this step in a loop until the 
preallocated size (default is 32 now) gets full. You should be able to go one 
more such a step over the full buffer (in order to trigger the resize) and 
this is basically the test that will show this bug.
The code that I inserted before fixes this issue.

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to