Uploaded image for project: 'JGroups'
  1. JGroups
  2. JGRP-2355

TCP_NIO2 fails under Java 8

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 4.1.2
    • 4.1.1
    • None

      Because the 4.1.x releases are built with JDK11, I see the following at runtime when running under Java 8:

      WARN  [org.jgroups.protocols.TCP_NIO2] (TQ-Bundler-6,ejb,node-1) node-1: failed sending message to 127.0.0.1:7700: java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear()Ljava/nio/ByteBuffer;
      

      The problematic code seems to be here:
      https://github.com/belaban/JGroups/blob/master/src/org/jgroups/blocks/cs/NioConnection.java#L398

      In JDK8, Buffer.clear() was final and returned a Buffer object (hence the need for your code to cast). However, in JDK11 Buffer.clear() is no longer final, allowing subclasses to override the return type, which ByteBuffer indeed does (to return a ByteBuffer). However, since JGroups 4.1.x is built with JDK11, when running on Java 8, the method is not found.

      N.B. There is a similar problem with uses of ByteBuffer.flip() and limit(...). I didn't catch these at first since NioConnection.Reader.run() swallows Errors.

      There are 2 ways to fix this:
      1. Ensure 4.1.x releases are built using JDK8 (since source is still compatible with Java 8)
      2. Cast java.io.ByteBuffer to java.nio.Buffer when invoking clear() to avoid the NoSuchMethodError.

            rhn-engineering-bban Bela Ban
            pferraro@redhat.com Paul Ferraro
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: