According to the JDBC specification, using getBytes on a BLOB column isn't allowed. This is stated in table B-6 and the following text:
TABLE B-6 Type Conversions Supported by ResultSet getter Methods
This table shows which JDBC types may be returned by ResultSet getter methods. A
bold X indicates the method recommended for retrieving a JDBC type. A plain x
indicates for which JDBC types it is possible to use a getter method.
There is no x/X in the cell where getBytes and BLOB intersects.
If this is correct, I will create a new JIRA to track the work on forbidding this in Derby since the title of this issue doesn't express what is changing very well. This change will most likely have consequences for some existing applications and will require a release note.
The work mentioned above is probably not suitable for backporting, but as an an alternative we could use the mechanism that disallows multiple accesses of the same LOB/stream column on a single row to improve the situation on 10.8 and earlier. That means applications using only ResultSet.getBytes() on a BLOB will continue to work, whereas applications using ResultSet.get[Blob|BinaryStream|Object] plus getBytes will fail. Failing with an exception is preferable to data corruption/wrong results. Some applications may not see the data corruption/wrong results - I believe this will be the case if the BLOBs are below a given threshold (represented in-memory vs store stream). Based on Dag's comment this may also be the case for applications using the client driver (independent of the BLOB size).
I haven't verified it, but I suspect there will be similar issues to fix for CLOB.
Any opinions on my interpretation of the JDBC specification, and on the suggested improvements?