alibaba/canal · error · NullPointerException

null zkClient

Error message

null zkClient

What it means

MixedLogPositionManager keeps positions in memory for speed and asynchronously mirrors them to ZooKeeper for durability. It builds both delegates from a single ZkClientx, so a null zkClient is fatal and the constructor throws NullPointerException. Without the zk client the durable mirror cannot be constructed.

Source

Thrown at parse/src/main/java/com/alibaba/otter/canal/parse/index/MixedLogPositionManager.java:28

import com.alibaba.otter.canal.parse.exception.CanalParseException;
import com.alibaba.otter.canal.protocol.position.LogPosition;

/**
 * Created by yinxiu on 17/3/17. Email: marklin.hz@gmail.com Memory first.
 * Asynchronous commit position info to ZK.
 */
public class MixedLogPositionManager extends AbstractLogPositionManager {

    private final Logger                      logger = LoggerFactory.getLogger(MixedLogPositionManager.class);

    private final MemoryLogPositionManager    memoryLogPositionManager;
    private final ZooKeeperLogPositionManager zooKeeperLogPositionManager;

    private final ExecutorService             executor;

    public MixedLogPositionManager(ZkClientx zkClient){
        if (zkClient == null) {
            throw new NullPointerException("null zkClient");
        }

        this.memoryLogPositionManager = new MemoryLogPositionManager();
        this.zooKeeperLogPositionManager = new ZooKeeperLogPositionManager(zkClient);

        this.executor = Executors.newFixedThreadPool(1);
    }

    @Override
    public void start() {
        super.start();

        if (!memoryLogPositionManager.isStart()) {
            memoryLogPositionManager.start();
        }

        if (!zooKeeperLogPositionManager.isStart()) {
            zooKeeperLogPositionManager.start();

View on GitHub (pinned to 87be50e876)

Solutions

  1. Set canal.zkServers to a reachable ZooKeeper cluster address before constructing the manager.
  2. Ensure ZkClientx is built and non-null (handle connection failures explicitly rather than passing null).
  3. For tests, use an embedded ZooKeeper TestingServer and pass a real ZkClientx.

Example fix

// before
new MixedLogPositionManager(null);

// after
ZkClientx zk = ZkClientx.getZkClient(zkServers);
new MixedLogPositionManager(Objects.requireNonNull(zk, "zkClient"));
Defensive patterns

Strategy: validation

Validate before calling

ZkClientx zk = Objects.requireNonNull(zkClient, "zkClient");
new MixedLogPositionManager(zk);

Type guard

boolean hasZkClient(ZkClientx z) { return z != null; }

Prevention

When it happens

Trigger: Calling `new MixedLogPositionManager(zkClient)` with zkClient == null. Occurs when the zookeeper address property is empty/unset, so the ZkClientx was never built, or the builder returned null on connection failure.

Common situations: `canal.zkServers` is not configured; a network issue during ZkClientx construction returned null; a test that forgets to provide a zk test server (e.g. embedded ZooKeeper).

Related errors


AI-assisted analysis of alibaba/canal@87be50e876 (2026-08-14). Data as JSON: /api/errors/d133b73c6a0c17f1. Report an issue: GitHub.