Status Update
Comments
vi...@google.com <vi...@google.com> #2
We have shared this with our product and engineering team and will update this issue with more information as it becomes available.
vi...@google.com <vi...@google.com> #3
Thanks for reporting this issue.
We have added the ByteBuffer flip()
method to the ByteBuffer
class to the runtime since Android 10 (API level 29) .
See @CovariantReturnType(returnType = ByteBuffer.class, presentAfter = 28)
However, calling this method from an app on Android 9 or older device will result in a app crash.
need to resort to cast so that compatible multi-platform bytecode is emitted.
The cast is necessary to be compatible with Android 9 or older device. (and necessary to run on OpenJDK 8, I believe)
Note that flip()
returns this buffer
. You don't normally need the return instance, but can keep using ByteBuffer bb
instance instead.
We will think about updating the Android SDK once Android 9 is not widely supported.
Description
Starting with Java 9, some methods of subclasses of JDK-4774077 .
java.nio.Buffer
, e.g.,ByteBuffer
, start to return the specific Buffer type, e.g.,ByteBuffer
instead of justBuffer
Examples include
flip()
andposition()
.Android never reflected this change and, for example, .
ByteBuffer.flip()
still returnsBuffer
instead ofByteBuffer
As a result, multi-platform libraries, i.e., libraries that target Android and Java either need to use "--release 8", which is undesirable, or need to resort to cast so that compatible multi-platform bytecode is emitted.
For example:
must become
which adds noise to the code.
To avoid this, please consider adjusting Android's API regarding NIO Buffers to match the current Java API.