Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException in Unsafe buffer wrapping a HeapByteBufferR #66

Closed
robertroeser opened this issue Jul 15, 2016 · 5 comments
Closed

Comments

@robertroeser
Copy link

Hi,

I'm getting a class cast exception using an UnsafeBuffer. Looks like HeapByteBufferR doesn't implement DirectBuffer and is causing problems. Here's the pertinent stack trace fragments:

java.lang.ClassCastException: java.nio.HeapByteBufferR cannot be cast to sun.nio.ch.DirectBuffer
    at org.agrona.concurrent.UnsafeBuffer.putBytes(UnsafeBuffer.java:891)
    at org.agrona.concurrent.UnsafeBuffer.putBytes(UnsafeBuffer.java:869)

Thanks,
Robert

@mjpt777
Copy link
Contributor

mjpt777 commented Jul 15, 2016

What JDK and by what means have you created the ByteBuffer?

@mjpt777
Copy link
Contributor

mjpt777 commented Jul 15, 2016

Also what version of Agrona are you using?

@mikeb01
Copy link
Contributor

mikeb01 commented Jul 15, 2016

The problem is that the buffer that is been passed to UnsafeBuffer is a readonly one. HeapByteBufferR will return false when calling hasArray() despite being heap allocated. The wrap call uses this to determine if this should be treated as a heap or direct buffer.

@mjpt777
Copy link
Contributor

mjpt777 commented Jul 15, 2016

@mikeb01 I just noticed this. Seems ready-only heap buffers give the wrong answers to hasArray() and throw and exception on array().

mjpt777 added a commit that referenced this issue Jul 15, 2016
…nly buffer then the exception is more informative until a better solution is found. Issue #66.
@mjpt777
Copy link
Contributor

mjpt777 commented Jul 15, 2016

This should now be consistent across direct and heap buffers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants