RFR: 8153490: Cannot setBytes() if incoming buffer's length is bigger than number of elements we want to insert.

Lance Andersen lance.andersen at oracle.com
Wed May 12 20:12:46 UTC 2021


I won’t have time to look at this today, might not be until over the weekend.

On May 12, 2021, at 2:07 PM, Mitsuru Kariya <github.com+2217224+kariya-mitsuru at openjdk.java.net<mailto:github.com+2217224+kariya-mitsuru at openjdk.java.net>> wrote:

Fix `SerialBlob.setBytes(long pos, byte[] bytes, int offset, int length)` in the following cases:

1. `pos - 1 + bytes.length - offset > this.length() && pos - 1 + length <= this.length()`
  The original implementation throws `ArrayIndexOutOfBoundsException` but this case should end successfully.
  (test31)

2. `pos - 1 + length > this.length()`
  The original implementation throws `ArrayIndexOutOfBoundsException` but this case should end successfully. *1
  (test32)

3. `pos == this.length() + 1`
  The original implementation throws `SerialException` but this case should end successfully. *2
  (test33)

Additionally, fix `SerialClob.setString(long pos, String str, int offset, int length)` in the following cases:

1. `offset > str.length()`
  The original implementaion throws `StringIndexOutOfBoundsException` but this case should throw `SerialException`.
  (test39)

2. `pos - 1 + str.length() - offset > this.length() && pos - 1 + length <= this.length()`
  The original implementation throws `ArrayIndexOutOfBoundsException` but this case should end successfully.
  (test32)

3. `pos - 1 + length > this.length()`
  The original implementaion throws `SerialException` but this case should end successfully. *3
  (test40)

4. `pos == this.length() + 1`
  The original implementaion throws `SerialException` but this case should end successfully. *4
  (test41)

The javadoc has also been modified according to the above.


The items below should  would change the spec change, require a CSR  and should be looked at separately

*1 The documentation of `Blob.setBytes()` says, "If the end of the Blob value is reached while writing the array of bytes, then the length of the Blob value will be increased to accommodate the extra bytes."

*2 The documentation of `Blob.setBytes()` says, "If the value specified for pos is greater than the length+1 of the BLOB value then the behavior is undefined."
  So, it should work correctly when pos == length+1 of the BLOB value.

*3 The documentation of `Clob.setString()` says, "If the end of the Clob value is eached while writing the given string, then the length of the Clob value will be increased to accommodate the extra characters."

*4 The documentation of `Clob.setString()` says, "If the value specified for pos is greater than the length+1 of the CLOB value then the behavior is undefined."
  So, it should work correctly when pos == length+1 of the CLOB value.

-------------

Commit messages:
- 8153490:Cannot setBytes() if incoming buffer's length is bigger than number of elements we want to insert.

Changes: https://git.openjdk.java.net/jdk/pull/4001/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=4001&range=00
 Issue: https://bugs.openjdk.java.net/browse/JDK-8153490
 Stats: 179 lines in 4 files changed: 122 ins; 17 del; 40 mod
 Patch: https://git.openjdk.java.net/jdk/pull/4001.diff
 Fetch: git fetch https://git.openjdk.java.net/jdk pull/4001/head:pull/4001

PR: https://git.openjdk.java.net/jdk/pull/4001

[cid:E1C4E2F0-ECD0-4C9D-ADB4-B16CA7BCB7FC at home]



Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037
Oracle Java Engineering
1 Network Drive
Burlington, MA 01803
Lance.Andersen at oracle.com<mailto:Lance.Andersen at oracle.com>





More information about the core-libs-dev mailing list