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

ByteBuffer.array() cannot always be used #837

Open
pjfanning opened this issue May 17, 2024 · 1 comment
Open

ByteBuffer.array() cannot always be used #837

pjfanning opened this issue May 17, 2024 · 1 comment

Comments

@pjfanning
Copy link
Contributor

pjfanning commented May 17, 2024

It is recommended to call ByteBuffer.hasArray before calling ByteBuffer.array()

avro4s calls array() in quite a few places.

https://github.com/search?q=repo%3Asksamuel%2Favro4s%20array()&type=code

See javadoc:
https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html#array--

Calling array() on a ByteBuffer that hasArray=false (eg a read-only byte buffer) will lead to an exception.

In the cases where hasArray=false, a decision needs to be made over whether you can iterate over the bytes of the Buffer using other ByteBuffer methods or whether you could do something like wrap the ByteBuffer in an enclosing class - eg something like ByteBufferBackedInputStream

@sksamuel
Copy link
Owner

Makes sense. If you want to raise a PR I would cut a release.

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

2 participants