alibaba/canal · critical · NullPointerException

nul primary LogPositionManager

Error message

nul primary LogPositionManager

What it means

Thrown as NullPointerException by the FailbackLogPositionManager constructor when the primary CanalLogPositionManager argument is null. This is a fail-fast constructor validation — the FailbackLogPositionManager requires both a primary and secondary manager to function as a failover pair.

Source

Thrown at parse/src/main/java/com/alibaba/otter/canal/parse/index/FailbackLogPositionManager.java:26

/**
 * Created by yinxiu on 17/3/18. Email: marklin.hz@gmail.com
 * 实现基于failover查找的机制完成meta的操作
 *
 * <pre>
 * 应用场景:比如针对内存buffer,出现HA切换,先尝试从内存buffer区中找到lastest position,如果不存在才尝试找一下meta里消费的信息
 * </pre>
 */
public class FailbackLogPositionManager extends AbstractLogPositionManager {

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

    private final CanalLogPositionManager primary;
    private final CanalLogPositionManager secondary;

    public FailbackLogPositionManager(CanalLogPositionManager primary, CanalLogPositionManager secondary){
        if (primary == null) {
            throw new NullPointerException("nul primary LogPositionManager");
        }
        if (secondary == null) {
            throw new NullPointerException("nul secondary LogPositionManager");
        }

        this.primary = primary;
        this.secondary = secondary;
    }

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

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

        if (!secondary.isStart()) {

View on GitHub (pinned to 87be50e876)

Solutions

  1. Ensure the primary CanalLogPositionManager bean is defined and injected — typically a MemoryLogPositionManager or ZooKeeperLogPositionManager.
  2. Check Spring/canal XML configuration for missing <constructor-arg> ref for the primary manager.
  3. Verify the primary bean is instantiated before the FailbackLogPositionManager bean.
  4. If constructing programmatically, ensure both primary and secondary are non-null before calling the constructor.

Example fix

// before
new FailbackLogPositionManager(null, secondaryManager);

// after
CanalLogPositionManager primary = new MemoryLogPositionManager();
new FailbackLogPositionManager(primary, secondaryManager);
Defensive patterns

Strategy: validation

Validate before calling

// Validate both managers before constructing FailbackLogPositionManager
if (primary == null) {
    throw new IllegalArgumentException("Primary LogPositionManager must not be null");
}
if (secondary == null) {
    throw new IllegalArgumentException("Secondary LogPositionManager must not be null");
}
FailbackLogPositionManager manager = new FailbackLogPositionManager(primary, secondary);

Prevention

When it happens

Trigger: Instantiating new FailbackLogPositionManager(null, secondary) — the primary argument is null. This is a wiring/configuration error, not a runtime data issue. It fails immediately at construction time.

Common situations: Spring/XML bean configuration missing the primary LogPositionManager bean reference; the primary bean failed to initialize and was null-wired; programmatic construction where the primary manager was not yet created; a refactoring that removed the primary bean definition.

Related errors


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