Skip to content

[Java] Avoid covariant ByteBuffer method references - #9225

Open
mjmahone wants to merge 1 commit into
google:masterfrom
mjmahone:fix-java-bytebuffer-covariance
Open

[Java] Avoid covariant ByteBuffer method references#9225
mjmahone wants to merge 1 commit into
google:masterfrom
mjmahone:fix-java-bytebuffer-covariance

Conversation

@mjmahone

@mjmahone mjmahone commented Sep 5, 2026

Copy link
Copy Markdown

Summary

Wehn using a different build system to compile Java from source, it's easy to get tripped up if your toolchain's default target release is > 8. Specifically ProGuard trips up due to covariant overrides for methods, specifically clear(), position(int), limit(int), flip(), and rewind().

We can route ByteBuffer calls through their Buffer base type to preserve behavior, while emitting java.nio.Buffer signatures.

Testing

  • Compiled all Java runtime sources with JDK 8.
  • Compiled all Java runtime sources with JDK 11, producing class-file version 55.

Java 9 added covariant ByteBuffer overrides for mutating methods such as clear(), position(int), limit(int), flip(), and rewind(). When these sources are compiled on a newer JDK without --release 8, javac emits references to those newer signatures, which are absent from Android API stubs and cause R8/ProGuard missing-method failures.

Invoke the inherited methods through Buffer so the generated bytecode uses signatures supported by Java 8 and Android. This is behavior-preserving and allows downstream Java and Kotlin targets to use newer bytecode levels.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant