]
Paul Ferraro commented on JGRP-2355:
------------------------------------
FWIW, this PR allows TCP_NIO2 to work under Java 8 even when built using JDK11.
TCP_NIO2 fails under Java 8
---------------------------
Key: JGRP-2355
URL:
https://issues.jboss.org/browse/JGRP-2355
Project: JGroups
Issue Type: Bug
Affects Versions: 4.1.1
Reporter: Paul Ferraro
Assignee: Bela Ban
Priority: Critical
Fix For: 4.1.2
Because the 4.1.x releases are built with JDK11, I see the following at runtime when
running under Java 8:
{noformat}
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;
{noformat}
The problematic code seems to be here:
https://github.com/belaban/JGroups/blob/master/src/org/jgroups/blocks/cs/...
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.