Bug #71623 Field#getStringFromBytes() creates useless byte array when using JVM converter
Submitted: 7 Feb 2014 12:42 Modified: 10 Mar 2014 23:41
Reporter: Andrej Golovnin (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S5 (Performance)
Version:5.1.29 OS:Any
Assigned to: Filipe Silva
Tags: field, jdbc

[7 Feb 2014 12:42] Andrej Golovnin
Description:
Field#getStringFromBytes() creates useless byte array when using JVM converter and an encoding defined by connection. It create a byte array in the lines 742-749 and calls the method StringUtils#toString(byte[], String) using the created byte array. But the method should call StringUtils#toString(byte[], int, int, String) using the original buffer instead and thus avoid the creation of a temp byte array.

How to repeat:
Use profiler to see how may temp byte arrays are created in the method Field#getStringFromBytes().

Suggested fix:
See description and the patch.
[7 Feb 2014 12:43] Andrej Golovnin
The patch to fix this issue.

Attachment: Field.patch (application/octet-stream, text), 848 bytes.

[11 Feb 2014 11:27] Filipe Silva
Hi Andrej,

Thank you for this bug report. Verified as described by code review.
[18 Feb 2014 13:50] Andrej Golovnin
Patch for this issue.

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: Field.patch (application/octet-stream, text), 848 bytes.

[21 Feb 2014 10:17] Alexander Soklakov
Thanks Andrej, accepted.
[10 Mar 2014 23:41] Daniel So
Added the following entry to the Connector/J 5.1.30 changelog:

"The Field.getStringFromBytes() method created a useless byte array when using JVM's converter and the encoding defined by the connection. This fix makes the method call StringUtils.toString() using the original buffer instead of creating a temporary byte array for the call."