You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Ekaterina Dimitrova (Jira)" <ji...@apache.org> on 2021/09/09 13:13:00 UTC

[jira] [Commented] (CASSANDRA-14752) serializers/BooleanSerializer.java is using static bytebuffers which may cause problem for subsequent operations

    [ https://issues.apache.org/jira/browse/CASSANDRA-14752?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17412564#comment-17412564 ] 

Ekaterina Dimitrova commented on CASSANDRA-14752:
-------------------------------------------------

Hey [~varuna], apologize for the very late response.

I think we can simplify a bit by reducing the patch to changing [this line|https://github.com/Barala/cassandra/commit/2328cda4d4e12e75bc1e9606969f18dd72d4fc27#diff-821957692da5432eb814312397d145fc6445ac35856563b21895e0c1df82ca3aL235]

to 
{code:java}
bb.put(component.duplicate()); // it's not ok to consume component as we did not create it{code}
What do you think?
[~blerer] , do you mind also to review it? I see it is also marked for 4.x but I think we can port it also to at least 4.0.x.

 

> serializers/BooleanSerializer.java is using static bytebuffers which may cause problem for subsequent operations
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-14752
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-14752
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Legacy/Core
>            Reporter: Varun Barala
>            Priority: Normal
>             Fix For: 4.x
>
>         Attachments: patch, patch-modified
>
>
> [https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/serializers/BooleanSerializer.java#L26] It has two static Bytebuffer variables:-
> {code:java}
> private static final ByteBuffer TRUE = ByteBuffer.wrap(new byte[]{1});
> private static final ByteBuffer FALSE = ByteBuffer.wrap(new byte[]{0});{code}
> What will happen if the position of these Bytebuffers is being changed by some other operations? It'll affect other subsequent operations. -IMO Using static is not a good idea here.-
> A potential place where it can become problematic: [https://github.com/apache/cassandra/blob/cassandra-2.1.13/src/java/org/apache/cassandra/db/marshal/AbstractCompositeType.java#L243] Since we are calling *`.remaining()`* It may give wrong results _i.e 0_ if these Bytebuffers have been used previously.
> Solution: 
>  [https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/serializers/BooleanSerializer.java#L42] Every time we return new bytebuffer object. Please do let me know If there is a better way. I'd like to contribute. Thanks!!
> {code:java}
> public ByteBuffer serialize(Boolean value)
> {
> return (value == null) ? ByteBufferUtil.EMPTY_BYTE_BUFFER
> : value ? ByteBuffer.wrap(new byte[] {1}) : ByteBuffer.wrap(new byte[] {0}); // false
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org