alibaba/canal · error · NullPointerException

null dataDir

Error message

null dataDir

What it means

FileMixedLogPositionManager caches positions in memory and periodically flushes them to files under a data directory. The constructor rejects a null dataDir with NullPointerException because there is no filesystem location to persist to. The directory is also created and permission-checked later in start(), but the null guard fires first at construction.

Source

Thrown at parse/src/main/java/com/alibaba/otter/canal/parse/index/FileMixedLogPositionManager.java:58

    private File                     dataDir;

    private Map<String, File>        dataFileCaches;

    private ScheduledExecutorService executorService;

    @SuppressWarnings("serial")
    private final LogPosition        nullPosition = new LogPosition() {
                                                  };

    private MemoryLogPositionManager memoryLogPositionManager;

    private long                     period;
    private Set<String>              persistTasks;

    public FileMixedLogPositionManager(File dataDir, long period, MemoryLogPositionManager memoryLogPositionManager){
        if (dataDir == null) {
            throw new NullPointerException("null dataDir");
        }
        if (period <= 0) {
            throw new IllegalArgumentException("period must be positive, given: " + period);
        }
        if (memoryLogPositionManager == null) {
            throw new NullPointerException("null memoryLogPositionManager");
        }
        this.dataDir = dataDir;
        this.period = period;
        this.memoryLogPositionManager = memoryLogPositionManager;

        this.dataFileCaches = MigrateMap.makeComputingMap(this::getDataFile);

        this.executorService = Executors.newScheduledThreadPool(1);
        this.persistTasks = Collections.synchronizedSet(new HashSet<>());
    }

    @Override

View on GitHub (pinned to 87be50e876)

Solutions

  1. Set the data directory property (e.g. canal.dataDir / canal.instance.position.dataDir) to a non-null path in canal.conf or the instance properties.
  2. If constructing manually, pass `new File("/your/canal/data")` and verify the File is non-null before calling the constructor.
  3. Confirm the config value is not blank or referencing an undefined placeholder.

Example fix

// before
new FileMixedLogPositionManager(null, period, memoryMgr);

// after
File dir = new File(Objects.requireNonNull(dataDirPath, "dataDirPath"));
new FileMixedLogPositionManager(dir, period, memoryMgr);
Defensive patterns

Strategy: validation

Validate before calling

File dir = new File(Objects.requireNonNull(dataDirPath, "dataDirPath"));
new FileMixedLogPositionManager(dir, period, memoryMgr);

Type guard

boolean isValidDataDir(File f) { return f != null; }

Prevention

When it happens

Trigger: Calling `new FileMixedLogPositionManager(dataDir, period, memoryLogPositionManager)` with dataDir == null. Typically the `canal.instance.position.dataDir` / `canal.dataDir` property is unset or resolves to a null File.

Common situations: The deployer's `canal.conf` or instance properties omit the data directory; running in a container where the configured data path env var is missing; a refactor that stopped injecting the dataDir File bean.

Related errors


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