Issue Details (XML | Word | Printable)

Key: DERBY-3977
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Kristian Waagan
Reporter: Kristian Waagan
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Derby

Clob.truncate with a value greater than the Clob length raises different exceptions in embedded and client driver

Created: 08/Dec/08 01:12 PM   Updated: 04/May/09 06:22 PM
Component/s: JDBC
Affects Version/s: 10.3.3.0, 10.4.2.0, 10.5.1.1
Fix Version/s: 10.5.1.1

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works derby-3977-1a-change_emb_exception.diff 2008-12-10 02:32 PM Kristian Waagan 2 kB
File Licensed for inclusion in ASF works derby-3977-2a-error_message_typo_fix.diff 2008-12-15 01:43 PM Kristian Waagan 4 kB
File Licensed for inclusion in ASF works derby-3977-2a-error_message_typo_fix.stat 2008-12-15 01:43 PM Kristian Waagan 0.1 kB
HTML File Licensed for inclusion in ASF works releaseNote.html 2008-12-15 01:40 PM Kristian Waagan 4 kB
HTML File Licensed for inclusion in ASF works releaseNote.html 2008-12-11 09:50 AM Kristian Waagan 4 kB

Issue & fix info: Release Note Needed
Bug behavior facts: Embedded/Client difference
Resolution Date: 05/Jan/09 11:30 AM


 Description  « Hide
Calling Clob.truncate with a value that is greater then the Clob length raises different SQLExceptions in the client and the embedded driver.
 o Client: SQLState.BLOB_LENGTH_TOO_LONG - XJ079
 o Embedded: SQLState.BLOB_POSITION_TOO_LARGE - XJ076

I believe the fix is simple enough - change one of the exceptions.
Which one most closely describes the situation?

A release note is needed for this fix.

Also note the following from the Java API docs:
"void truncate(long len)
              throws SQLException

    Truncates the CLOB value that this Clob designates to have a length of len characters.

    Note: If the value specified for pos is greater then the length+1 of the CLOB value then the behavior is undefined. Some JDBC drivers may throw a SQLException while other drivers may support this operation.
"

This opens for a change of behavior as well.
There seems to an inconsistency in the docs, possibly due to rephrasing - it references both len and pos. The latter isn't used anywhere else in the JavaDoc for truncate.
And what should the result of truncate(length+1) be?

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Knut Anders Hatlen added a comment - 09/Dec/08 12:55 PM
Since it's a length and not a position, I guess the exception thrown by the client is more accurate.

If we throw exceptions for length+2 and up, I think it's reasonable to throw an exception for length+1 as well, even though the wording in the spec is a bit unclear. Do we have any other alternatives?

Kristian Waagan added a comment - 09/Dec/08 02:32 PM
We don't have any good alternatives in my opinion, but I'm curious about what the databases that do support truncating to length+1 do!

I'll make a patch for the issue.

Kristian Waagan made changes - 09/Dec/08 02:32 PM
Field Original Value New Value
Assignee Kristian Waagan [ kristwaa ]
Knut Anders Hatlen added a comment - 09/Dec/08 03:26 PM
PostgreSQL's JDBC driver doesn't appear to throw an exception for len>=length+1. In code called from Clob.truncate(), I found this comment:

    /**
     * Truncates the large object to the given length in bytes.
     * If the number of bytes is larger than the current large
     * object length, the large object will be filled with zero
     * bytes. This method does not modify the current file offset.
     */

The comment talks about bytes, but the code is also used for character data, so I guess truncate(length+1) appends "\u0000".

MySQL Connector/J throws an exception, if I read the code correctly.

Kathey Marsden added a comment - 09/Dec/08 04:50 PM
JCC 3.57 with DB2 throws an SQLException, SQLState 42815. Invalid length x

Kristian Waagan added a comment - 10/Dec/08 02:32 PM
Patch 1a changes the exception thrown in the embedded driver from XJ076 to XJ079. It now matches the client driver.
I ran derbyall and suites.All, and got no failures due to the change of exception (except for the two new tests, which I have modified in the patch).

Patch ready for review.

Kristian Waagan made changes - 10/Dec/08 02:32 PM
Attachment derby-3977-1a-change_emb_exception.diff [ 12395738 ]
Kristian Waagan made changes - 10/Dec/08 02:32 PM
Affects Version/s 10.5.0.0 [ 12313010 ]
Derby Info [Release Note Needed] [Patch Available, Release Note Needed]
Kristian Waagan added a comment - 11/Dec/08 09:50 AM
Attached a first revision of the release notes. Please give me feedback on it.

I also discovered a typo in the error message for one of the exceptions.
Fixing that doesn't warrant another release note, does it?

Kristian Waagan made changes - 11/Dec/08 09:50 AM
Attachment releaseNote.html [ 12395820 ]
Knut Anders Hatlen added a comment - 12/Dec/08 02:28 PM
The release note looks good to me. Some minor comments:
Perhaps the example error messages should have a real number instead of {0} in them? And maybe that section is clearer if we say "Before: XJ076: ...." and "Now: XJ079: ....".
In the "Application Changes Required" section, we should repeat that it's only when calling Clob.truncate() one should look for XJ079 instead of XJ076, since we still use XJ076 other places. For example: "Look for SQLState XJ079 instead of XJ076 when Clob.truncate() is called."

Kristian Waagan added a comment - 15/Dec/08 01:40 PM
Thank you for the feedback, Knut Anders.

Attaching new revision of the release notes where the suggested changes have been addressed.

Kristian Waagan made changes - 15/Dec/08 01:40 PM
Attachment releaseNote.html [ 12396094 ]
Kristian Waagan added a comment - 15/Dec/08 01:43 PM
Patch 2a fixes the typo in the error message. The XML file and 4 translation files are touched.

Kristian Waagan made changes - 15/Dec/08 01:43 PM
Repository Revision Date User Message
ASF #726695 Mon Dec 15 13:47:59 UTC 2008 kristwaa DERBY-3977: Clob.truncate with a value greater than the Clob length raises different exceptions in embedded and client driver.
Changed the exception thrown in the embedded driver when calling Clob.truncate with a length greater than the Clob length from XJ076 to XJ079 (see also release note).
The client and the embedded driver behavior is now consistent.
Updated tests.

Patch file: DERBY-3977-1a-change_emb_exception.diff
Files Changed
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java

Kristian Waagan added a comment - 15/Dec/08 01:48 PM
Committed patch 1a to trunk with revision 726695.

Kristian Waagan made changes - 15/Dec/08 01:48 PM
Derby Info [Release Note Needed, Patch Available] [Patch Available, Release Note Needed]
Fix Version/s 10.5.0.0 [ 12313010 ]
Knut Anders Hatlen added a comment - 16/Dec/08 12:02 PM
Thanks for the updated release note. It looks good to me.

Kristian Waagan added a comment - 05/Jan/09 11:30 AM
Issue has been fixed.
Thanks for the feedback on the release notes, Knut Anders.

Kristian Waagan made changes - 05/Jan/09 11:30 AM
Derby Info [Release Note Needed, Patch Available] [Release Note Needed]
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Kristian Waagan added a comment - 08/Jan/09 11:32 AM
Release note attached and the issue has been fixed. Closing.

Kristian Waagan made changes - 08/Jan/09 11:32 AM
Status Resolved [ 5 ] Closed [ 6 ]
Myrna van Lunteren made changes - 04/May/09 06:22 PM
Fix Version/s 10.5.0.0 [ 12313010 ]
Fix Version/s 10.5.1.1 [ 12313771 ]
Affects Version/s 10.5.0.0 [ 12313010 ]
Affects Version/s 10.5.1.1 [ 12313771 ]