Published 09 Oct, 2022

Java - Kafka with Zookeeper 3.5.7 Crash NoSuchMethodError: java.nio.ByteBuffer.flip()

Category Java
Modified : Dec 01, 2022
31

I am facing this error stream

2020-03-10 13:43:33 NIOServerCnxnFactory [ERROR] Thread Thread[NIOWorkerThread-7,5,main] died
java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;
    at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:331)
    at org.apache.zookeeper.server.NIOServerCnxnFactory$IOWorkRequest.doWork(NIOServerCnxnFactory.java:530)
    at org.apache.zookeeper.server.WorkerService$ScheduledWorkRequest.run(WorkerService.java:155)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
...

using Java version

openjdk version "1.8.0_232"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.232-b09, mixed mode)

I am facing this problem when starting kafka 2.4.0 with zookeeper 3.5.7 on local mac Os Catalina, installed with homebrew. How to solve this?

Answers

There are 2 suggested solutions here and each one has been listed below with a detailed description. The following topics have been covered briefly such as Java, Macos, Homebrew, Apache Kafka, Apache Zookeeper. These have been categorized in sections for a clear and precise explanation.

56

It's explained in other service like hazelcast and dopio that this was caused by backward compatibility issue from jdk 9 to jdk 8.

There are 2 obvious options, either you:

  1. Update your jdk to 9

  2. Downgrade your zookeeper to 3.4.x

I chose to downgrade my zookeeper to 3.4.14 by using:

# force install zookeeper first
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/6d8197bbb5f77e62d51041a3ae552ce2f8ff1344/Formula/zookeeper.rb

# then force install kafka compatible with zookeeper 3.4.14
brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/6d8197bbb5f77e62d51041a3ae552ce2f8ff1344/Formula/kafka.rb

18

Uninstall 3.5.7's zookeeper with brew with brew uninstall zookeeper, and then install 3.4.14's zookeeper

Download link from https://zookeeper.apache.org/releases.html or https://mirrors.cnnic.cn/apache/zookeeper