harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Khaschansky" <oleg.v.khaschan...@gmail.com>
Subject Re: [classlib][sql] SerialBlob.setBytes exception thrown compatibility issue
Date Mon, 18 Dec 2006 17:19:14 GMT
Looking into this I noticed another strange thing. Look at the
following example:
        SerialBlob blob = new SerialBlob(new byte[255]);
        blob.setBytes(1, new byte[]{1}, 0, 1); // works fine
        blob.setBytes(1, new byte[]{}, 0, 1); // throws SerialException
the third line throws SerialException with the following message on RI:

javax.sql.rowset.serial.SerialException: Invalid OffSet. Cannot have
combined offset and length that is greater that the Blob buffer

It says that the blob buffer is too small, but it is large in fact!
The only difference with the second line is that the bytes array
became too small. So this message is invalid.

I think that the check of the form ((pos - 1+ length) <=
this.length()) is simply missing in RI, which results in the
ArrayIndexOutOfBoundsException's.

+1 for having this check and throwing SerialException instead of
following RI in this case.


On 12/18/06, Andrew Zhang <zhanghuangzhu@gmail.com> wrote:
> Hi guys,
>
> It's SerialBlob again. It's the third time to ask similar question about
> SerialBlob class. :)
> Let's take a look at the spec of setBytes(long pos,byte [] bytes, int
> offset, int length).   Throws SerialException - if there is an error
> accessing the BLOB value; if an invalid position is set; if an invalid
> offset value is set; if number of bytes to be written is greater than the
> SerialBlob length; or the combined values of the length and offset is
> greater than the Blob buffer
>
> As my understanding, the tortuous words shows that setBytes should throw
> SerialException if there's any array index outbound. But following code
> shows that RI's behaviour looks weird:
> public void testSetBytes() throws Exception {
>         byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
>         byte[] theBytes = { 9, 9, 9 };
>         SerialBlob serialBlob = new SerialBlob(buf);
>         serialBlob.setBytes(7, theBytes); // ArrayIndexOutOfBoundsException
>         serialBlob.setBytes(7, theBytes, 0, 3); //
> ArrayIndexOutOfBoundsException
>         serialBlob.setBytes(7, theBytes, 0, 10); // SerialException
>     }
> Let's look at the spec again, what does "the combined values of the length
> and offset is greater than the Blob buffer " mean? The previous sentence
> already says "if number of bytes to be written (length) is greater than the
> SerialBlob length(Blob buffer)".
>
> The spec of another similar method setBytes(long pos, byte[] bytes) looks
> more interesting:
> SerialException - if there is an error accessing the BLOB value; or if an
> invalid position is set; if an invalid offset value is set
> But who can tell me what does "if an invalid offset value is set" mean? :-)
>
> The SerialBlob class looks scary to me.  What shall we do for setBytes?
> Follow RI or always throw SerialException for invalid array index?
> Personally I prefer to the latter one, and if it breaks any existing
> application or fails TCK tests later, then let's fix it. Any
> suggestions/comments? Thanks in advance!
>
>
> --
> Best regards,
> Andrew Zhang
>
>

Mime
View raw message