[ 
https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12515029
 ] 

Daniel John Debrunner commented on DERBY-2936:
----------------------------------------------

In DDMWriter is there a good reason to keep the byte[] bytes field?

It's basically a bug waiting to happen, for bytes and buffer to get out of 
sync. I had to waste time going through the code to ensure that they currently 
are kept in sync.

Why not just use buffer.array() anytime direct access to the array is required. 
Then it's clearly visible in the method that they will be in sync.


> Use java.nio.ByteBuffer for buffering in DDMWriter
> --------------------------------------------------
>
>                 Key: DERBY-2936
>                 URL: https://issues.apache.org/jira/browse/DERBY-2936
>             Project: Derby
>          Issue Type: Improvement
>          Components: Network Server
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>             Fix For: 10.4.0.0
>
>         Attachments: d2936-1.diff, derby-2936-2.diff, derby-2936-2.stat
>
>
> org.apache.derby.impl.drda.DDMWriter uses a byte array as a buffer. Wrapping 
> the array in a java.nio.ByteBuffer has some advantages, for instance:
>   - utility methods for encoding primitive types into the byte array could be 
> used instead of manually encoding the values
>   - it allows us to encode strings directly into the buffer (using a 
> CharsetEncoder) without doing an expensive String.getBytes(String encoding) 
> in an intermediate step
> By using a utility class, the code becomes easier to maintain. Also, 
> ByteBuffer allows us to access the backing byte array without going through 
> the ByteBuffer interface, so we still have the possibility to modify the byte 
> array directly in cases where that's more convenient.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to