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

Sylvain Lebresne commented on CASSANDRA-12381:
----------------------------------------------

bq. A direct buffer with an array feels very weird.  At least with the current 
state of OpenJDK/Oracle Java.

Maybe, but the javadoc is the spec, not our current knowledge of any specific 
implementation or our personal sentiment of what the spec should be. My reading 
of the Netty ticket (thanks for the link) is that Netty was assuming 
{{hasArray()}} => {{isDirect()}}, which is clearly a violation of the spec, but 
they don't seem to have had any problem accessing the backing buffer of a 
direct buffer. And again, the spec seems pretty clear to me on the fact that 
*if* a direct buffer returns {{true}} for {{hasArray()}} (no matter how rare 
this is), then the array returned by {{array}} should be safe to use. And as 
far as I can tell, we always use {{hasArray}} properly, as a guard before 
calling {{array}}, and I strongly think we should keep {{hasArray()}} for this, 
since that's much more explicit. Of course, if there is a few places where we 
misuse {{hasArray()}} as a mean to know if the buffer is not direct, then we 
should fix those, but I doubt we do that much, if ever (the Netty case is 
pretty special here).

> Verify use of ByteBuffer.hasArray() in whole code base
> ------------------------------------------------------
>
>                 Key: CASSANDRA-12381
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-12381
>             Project: Cassandra
>          Issue Type: Bug
>            Reporter: Robert Stupp
>            Assignee: Robert Stupp
>            Priority: Minor
>             Fix For: 3.0.x
>
>
> As [noted 
> here|https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html#allocateDirect-int-],
>  a direct {{ByteBuffer}} can have a backing array.
> If a direct {{ByteBuffer}} has a backing array, we should not make any 
> assumption on how it is actually used.
> This ticket is about to check whether uses of {{ByteBuffer.hasArray()}} need 
> to be replaced with {{ByteBuffer.isDirect()}}.
> (With CASSANDRA-11870 however, there is no way that such a direct 
> {{ByteBuffer}} has a backing array.)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to