|
[
Permlink
| « Hide
]
Fernanda Pizzorno added a comment - 16/Aug/05 09:30 PM
Change method write (byte[], int, int) in java/client/org/apache/derby/client/am/BlobOutputStream.java. offset_ was not being incremented.
While you are at it:
In my program there is a line of code: java.io.OutputStream outstream = blob.setBinaryStream(1l); My original attempt was with blob.setBinaryStream(0l), as it should be in my opinion, but then the first byte written to the Blob does not get written, i.e. the resulting Blob is one byte short. By trial and error I found that it works when I use 1 instead of 0. Is that also a bug or is that intended? It also surprised me that it would start form 1, but it is intended to be so that the first byte is 1 and not 0.
The bugfix looks ok.
My comments do not concern the fix, but the patch itself: - BlobOutputStream.java: The System.arraycopy() line's diff is just a different ordering of subtraction and addition - same behaviour as before. - blobclob4BLOB.java: A blank line removed, and an added javadoc header without a function - should probably go into blobSetBinaryStream.java? - blobSetBinaryStream.java: * No newline at end of file * The 'isDerbyNet' variable seems to be unused * Do you need the 'startJBMS()' and 'setAutoCommit()' calls after the call to testBlob1() in main()? ...and maybe this is a little picky, but: * Some lines are not properly indented in main(). * Some typos in the string literals: "setBinaryStram", "mutiple" (don't forget to update the master file also). You will usually catch things such ac unnecessary diffs yourself by looking closely at the patch before submitting it. :) Committed revision 233487.
I wonder if similar problem exists if write(int) method is used, instead of write(b[], int, int) method. It seems the offset is not incremented in this case either. Looking at ClobOutputStream.java, does this need patching too?
Check if clobs have a similar problem, and extend the test to use both write(byte[], int, int) and write(int).
- The test blobSetBinaryStreams.java was only testing the write(byte[], int, int) method for blobs. I have extendedit so that it would use both write(byte[], int, int) and write(int) for both blobs and clobs. Since it was not a blob specific test, I have renamed it to lobStreams.java.
- Similar problems as the one fixed in the previous patch (the offset was not being incremented) existed in write(int) (for clobs and blobs) and write(byte[], int, int) (for clobs). These problems have now been fixed. - I have run derbyall successfully, except for store/encryptionKey.sql that failed, but I don't think it was related to my patch. On the 08/Sep/05 I attached a new patch for this issue containing a fix for Clobs (write(byte[], int, int) and write(int)) and blobs (write(int)). I forgot to ask someone to review the patch. So could someone please review it?
Submitted this patch. Thanks for addressing my review comments and fixing other API calls too. I do like your new test!
Looks like you haven't signed an ICLA with Apache... I would advise considering this step as your patches are getting bigger ...! Sending java\client\org\apache\derby\client\am\BlobOutputStream.java Sending java\client\org\apache\derby\client\am\ClobOutputStream.java Deleting java\testing\org\apache\derbyTesting\functionTests\master\blobSetBinaryStream.out Adding java\testing\org\apache\derbyTesting\functionTests\master\lobStreams.out Sending java\testing\org\apache\derbyTesting\functionTests\suites\derbynetclientmats.runall Deleting java\testing\org\apache\derbyTesting\functionTests\tests\jdbcapi\blobSetBinaryStream.java Deleting java\testing\org\apache\derbyTesting\functionTests\tests\jdbcapi\blobSetBinaryStream_app.properties Sending java\testing\org\apache\derbyTesting\functionTests\tests\jdbcapi\build.xml Sending java\testing\org\apache\derbyTesting\functionTests\tests\jdbcapi\copyfiles.ant Adding java\testing\org\apache\derbyTesting\functionTests\tests\jdbcapi\lobStreams.java Adding java\testing\org\apache\derbyTesting\functionTests\tests\jdbcapi\lobStreams_app.properties Transmitting file data ........ Committed revision 330687. I have one comment on this fix.
In ClobOutputStream.java public void write(int b) throws java.io.IOException { + byte[] newByte = new byte[1]; + newByte[0] = (byte)b; I think it is incorrect to cast int to a byte. This will lead to incorrect results for unicode characters whose value is greater than a byte. Sunitha, I don't think that is a problem because the api for OutputStream.write(int b) is that it is a write of a byte, the top 24 bits are discarded.
There is a different serious problem with the class, nothing to do with this patch, it's an existing problem. The code use String(byte[]) to create a string from a byte array. This uses the default platform encoding, which is typically not required behaviour. Since this class is used for Clob.setAsciiStream I assume the encoding should be ascii based. Though the performance of this class looks terrible if write(int) is used, at least five objects created for eveny byte written! In fact this class and the client Clob have code like this everywhere, as the Clob is updated: clob_.string_ = clob_.string_.concat(new String(newByte)); clob_.asciiStream_ = new java.io.StringBufferInputStream(clob_.string_); clob_.unicodeStream_ = new java.io.StringBufferInputStream(clob_.string_); clob_.characterStream_ = new java.io.StringReader(clob_.string_); Would probably be better to create most of those objects on demand, rather than on every modification. I mean if the CLOB is modified but the application never retrieives the ascii or character streams, what was the benefit of creating them? Looks like this patch has been committed for sometime... Fernanda, can you resolve the defect and after confirming the fix, can you also close the bug?
Attaching 'derby-463-v10.1.diff' which ports this fix to 10.1 branch. This port is required to merge and test
With this patch, I ran derbyall in v10.1 with Sun jdk 1.4.2 on Windows XP. Please take a look at this patch. Thanks. Committed to 10.1 with revision 407391.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||