alibaba/canal · error · NullPointerException
dbMapping.targetTable
Error message
dbMapping.targetTable
What it means
Thrown as NullPointerException by MappingConfig.validate when, for a non-mirrorDb config, dbMapping.targetTable is null or empty. targetTable is the destination ClickHouse table name; required for non-mirrorDb configs. mirrorDb configs are exempt because they derive target tables automatically.
Source
Thrown at client-adapter/clickhouse/src/main/java/com/alibaba/otter/canal/client/adapter/clickhouse/config/MappingConfig.java:92
}
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; // 目标表不区分大小写,默认是否
private String etlCondition; // etl条件sql
View on GitHub (pinned to 87be50e876)
Solutions
- Set dbMapping.targetTable to the destination ClickHouse table name (even if identical to table).
- For whole-DB mirroring, set dbMapping.mirrorDb: true to bypass the requirement.
- Verify YAML indentation and restart the adapter.
Example fix
# before: dbMapping: database: shop table: 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.getTargetTable() == null || m.getTargetTable().isEmpty())) {
throw new IllegalArgumentException("dbMapping.targetTable is required for non-mirrorDb config (file: " + fileName + ")");
} Prevention
- Always set dbMapping.targetTable, even when it equals the source table name.
- Use mirrorDb:true for whole-database mirroring to bypass the requirement.
- Lint configs in CI to catch a missing targetTable.
When it happens
Trigger: A non-mirror mapping yml omitting targetTable; targetTable set to empty; intending source and target names to be equal but leaving the field blank (it is not auto-defaulted from table).
Common situations: Configuring a sync where the target ClickHouse table name was assumed to default to the source table name (it does not); template with blank targetTable; YAML indentation error.
Related errors
- dbMapping.database
- dbMapping.table
- ERROR Config: {} {}
- No clickhouse adapter found for config key: {}
- not allow to change outAdapterKey
AI-assisted analysis of alibaba/canal@87be50e876 (2026-08-14).
Data as JSON: /api/errors/58facff5a57c0ace.
Report an issue: GitHub.