Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2559

Handle Java 9 additions of covariant return types to java.nio.ByteBuffer methods

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.6.0
    • Component/s: Internal
    • Labels:
      None
    • # Replies:
      1
    • Last comment by Customer:
      true
    • Epic Link:
    • Sprint:
      JVM Sprint 40

      Description

      Java 9 introduces overridden methods with covariant return types for the following methods in java.nio.ByteBuffer that are used by the driver:

      • position
      • limit
      • flip
      • clear

      In Java 9 they all now return ByteBuffer, whereas the methods they override return Buffer,
      resulting in exceptions like this when executing on Java 8 and lower:

      java.lang.NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer

      This is because the generated byte code includes the static return type of the method, which is not found on Java 8 and lower because the overloaded methods with covariant return types don't exist.

      The solution is to cast ByteBuffer instances to Buffer before calling the method.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                39 weeks, 3 days ago
                Date of 1st Reply: