Bug #34677 Blob.truncate throws exception with len < 1, should be < 0
Submitted: 19 Feb 2008 21:33 Modified: 1 Mar 2008 12:32
Reporter: Robert Nice Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.5 OS:Any
Assigned to: CPU Architecture:Any
Tags: BLOB, truncate

[19 Feb 2008 21:33] Robert Nice
Description:
Can't truncate a blob to zero bytes.

Javadoc:
     * @exception SQLException if there is an error accessing the
     *            <code>BLOB</code> value or if len is less than 0

But Code says:
        if (len < 1) {
            throw SQLError.createSQLException("\"len\" argument can not be < 1.",
                    SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
        }

Should be < 0 if own Javadoc (and expectations) are to be believed.

How to repeat:
myblob.truncate(0L);

Suggested fix:
Change < 1 to < 0
[20 Feb 2008 16:56] Tonci Grgin
Hi Robert and thanks for spotting this!

Thanks for your interest in MySQL.
[20 Feb 2008 17:13] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/42673
[27 Feb 2008 17:12] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/43086
[1 Mar 2008 12:32] MC Brown
A note has been added to the 5.1.6 changelog: 

It was not possible to truncate a BLOB using Blog.truncate() when using 0 as an argument.