Skip to content

Fix compatibility with java 9+#43

Merged
cretz merged 1 commit intocretz:masterfrom
DCNick3:fix-java-9-buffer-covariant-return-type
Jun 16, 2023
Merged

Fix compatibility with java 9+#43
cretz merged 1 commit intocretz:masterfrom
DCNick3:fix-java-9-buffer-covariant-return-type

Conversation

@DCNick3
Copy link
Contributor

@DCNick3 DCNick3 commented Jun 16, 2023

Java 9 introduced something called "covariant return types". This gets used in java.nio.ByteBuffer: overridden methods from java.nio.Buffer now return ByteBuffer instead of more general Buffer. Unfortunately this breaks bytecode generation for the memory: ByteBuffer::limit cannot be casted to ByteBuffer.(Int) -> Buffer. It can be casted to ByteBuffer.(Int) -> ByteBuffer, but not in java 8.

The fix is easy enough: upcast the object to Buffer before calling the method. In bytecode this corresponds to using Buffer::limit method instead of ByteBuffer::limit. This works both with older and newer java.

The same applies to Buffer::position

Arguably, one can change other references to ByteBuffer methods to the parent Buffer interface, but I decided to keep the changes minimal.

Closes #28. Supersedes #31.

Java 9 introduced something called "covariant return types". This gets
used in java.nio.ByteBuffer: overriden methods from java.nio.Buffer now
return ByteBuffer instead of more general Buffer. Unfortunately this
breaks bytecode generation for the memory: ByteBuffer::limit cannot be
casted to ByteBuffer.(Int) -> Buffer. It can be casted to
ByteBuffer.(Int) -> ByteBuffer, but not in java 8.

The fix is easy enough: upcast the object to Buffer before calling the
method. In bytecode this corresponds to using Buffer::limit method instead
of ByteBuffer::limit. This works both with older and newer java.

The same applies to Buffer::position
@cretz
Copy link
Owner

cretz commented Jun 16, 2023

Blind approving/merging because I don't work on this project as much anymore. Thanks!

@cretz cretz merged commit 82a5df2 into cretz:master Jun 16, 2023
@MihaelIsaev
Copy link

Hey guys could you please release the new version with the fix?

@cretz
Copy link
Owner

cretz commented Jun 19, 2023

I will set a reminder to make a release. It may be a while since I don't work on this much anymore.

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

Successfully merging this pull request may close these issues.

asmble compile error

3 participants