alibaba/canal · error · NullPointerException

dbMapping.table

Error message

dbMapping.table

What it means

Thrown as NullPointerException by MappingConfig.validate when, for a non-mirrorDb config, dbMapping.table is null or empty. table is the source table name; it is required unless mirrorDb is true (mirror mode replicates the whole database and does not need a per-table mapping).

Source

Thrown at client-adapter/clickhouse/src/main/java/com/alibaba/otter/canal/client/adapter/clickhouse/config/MappingConfig.java:89

    public String getDestination() {
        return destination;
    }

    public void setDestination(String destination) {
        this.destination = destination;
    }

    public AdapterMapping getMapping() {
        return dbMapping;
    }

    public void validate() {
        if (dbMapping.database == null || dbMapping.database.isEmpty()) {
            throw new NullPointerException("dbMapping.database");
        }
        if (!dbMapping.getMirrorDb() && (dbMapping.table == null || dbMapping.table.isEmpty())) {
            throw new NullPointerException("dbMapping.table");
        }
        if (!dbMapping.getMirrorDb() && (dbMapping.targetTable == null || dbMapping.targetTable.isEmpty())) {
            throw new NullPointerException("dbMapping.targetTable");
        }
    }

    public static class DbMapping implements AdapterMapping {

        private boolean             mirrorDb        = false;                 // 是否镜像库
        private String              database;                                // 数据库名或schema名
        private String              table;                                   // 表名
        private Map<String, String> targetPk        = new LinkedHashMap<>(); // 目标表主键字段
        private boolean             mapAll          = false;                 // 映射所有字段
        private String              targetDb;                                // 目标库名
        private String              targetTable;                             // 目标表名
        private Map<String, String> targetColumns;                           // 目标表字段映射

        private boolean             caseInsensitive = false;                 // 目标表不区分大小写,默认是否

View on GitHub (pinned to 87be50e876)

Solutions

  1. Set dbMapping.table to the source table name in the yml.
  2. If whole-database mirroring is intended, set dbMapping.mirrorDb: true instead (then table is not required).
  3. Check YAML indentation and restart the adapter.

Example fix

# before:
dbMapping:
  database: shop
  targetTable: orders
# after:
dbMapping:
  database: shop
  table: orders
  targetTable: orders
Defensive patterns

Strategy: validation

Validate before calling

MappingConfig.DbMapping m = config.getDbMapping();
if (!m.getMirrorDb() && (m.getTable() == null || m.getTable().isEmpty())) {
    throw new IllegalArgumentException("dbMapping.table is required for non-mirrorDb config (file: " + fileName + ")");
}

Prevention

When it happens

Trigger: A non-mirror mapping yml omitting the table field; table set to empty; indentation placing table outside dbMapping.

Common situations: Setting up a per-table sync and forgetting the source table name; partially converting a config to mirrorDb (mirrorDb left false) while dropping table; template with a blank table.

Related errors


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