Re: patch: tiny patch to correct stringbuffer size estimate - Mailing list pgsql-jdbc

From Barry Lind
Subject Re: patch: tiny patch to correct stringbuffer size estimate
Date
Msg-id 3F1D61D8.6030508@xythos.com
Whole thread Raw
In response to Re: patch: tiny patch to correct stringbuffer size estimate  (Felipe Schnack <felipes@ritterdosreis.br>)
Responses Re: patch: tiny patch to correct stringbuffer size estimate
List pgsql-jdbc
Felipe,

Why do you think the synchronizations are unnecessary?

Consider the following code:

    synchronized (sbuf)
    {
        sbuf.setLength(0);
        sbuf.ensureCapacity(x.length() + (int)(x.length() / 10));
        sbuf.append('\'');
        escapeString(x, sbuf);
        sbuf.append('\'');
        bind(parameterIndex, sbuf.toString(), type);
    }

If two thread where to perform this code at the same time using the same
sbuf the results would be garbage even if the methods on sbuf are all
syncronized.  It is the set of actions on sbuf here that needs to be
syncronized, not each individual call.  I beleive all the uses of
synchronization in the driver are of a similar usage pattern.

thanks,
--Barry

Felipe Schnack wrote:
>   These StringBuffer woes remember of an old request we made to this list... The last time I checked driver's
sources,all acess to preparedstatement's stringbuffer are synchronized... this isn't necessary as jre's Stringbuffer
alreadyhas all of its methods synchronized. 
>   The driver is still doing that? Just curious.
>
> On Wed, 23 Jul 2003 01:54:53 +1200
> Oliver Jowett <oliver@opencloud.com> wrote:
>
>
>>This patch tweaks the size estimate when escaping strings to count the
>>enclosing quotes.
>>
>>-O
>>
>
>
>




pgsql-jdbc by date:

Previous
From: Barry Lind
Date:
Subject: Re: Patch applied for SQL Injection vulnerability for setObject(int,Object,int)
Next
From: Felipe Schnack
Date:
Subject: Re: patch: tiny patch to correct stringbuffer size estimate