Hi folks,

I encountered another compatibility issue (the fourth one?) of SerialBlob
class. It's about truncate(long length) method. Spec says "Throws
SerialException - if there is an error accessing the Blob value; or the
length to truncate is greater that the SerialBlob length". But it doesn't
mention what happens if the length is negative. I tried following test code:

public void testTruncateJ() throws Exception {
       byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
       SerialBlob serialBlob1 = new SerialBlob(buf);
       try {
           serialBlob1.truncate(-1);
       } catch (SerialException e) {
           System.out.println(e.getMessage());
       }
       System.out.println(serialBlob1.length());
}
The RI output is:
Invalid arguments: position cannot be less that 1
-1
The first output SerialException is quite reasonable and the message also
sounds good. But the length is then changed to -1. IMO, if truncate method
regards -1 as an illegal argument, it should not change the length value
anyway. So I suggest that Harmony throws SerialException as RI and doesn't
change the length value (any internal data of serial blob). What's your
opnion? Thanks in adavance!

--
Best regards,
Andrew Zhang

Reply via email to