[jboss-jira] [JBoss JIRA] (JGRP-2355) TCP_NIO2 fails under Java 8
Paul Ferraro (Jira)
issues at jboss.org
Thu Jun 20 11:15:00 EDT 2019
[ https://issues.jboss.org/browse/JGRP-2355?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul Ferraro updated JGRP-2355:
-------------------------------
Description:
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/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(). 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.
was:
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/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.
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.
> 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/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(). 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.
--
This message was sent by Atlassian Jira
(v7.12.1#712002)
More information about the jboss-jira
mailing list