MyCATApache/Mycat-Server · critical · RuntimeException

clusterId and zkURL and myid must not be null or empty!

Error message

clusterId and zkURL and myid must not be null or empty!

What it means

After loading myid.properties, LoadMyidPropersites validates that clusterId, zkURL and myid are non-null and non-empty (using Guava Strings.isNullOrEmpty). If any of the three keys is missing or blank, it throws this RuntimeException. It is a startup fail-fast check for mandatory ZooKeeper connection properties.

Solutions

  1. Open myid.properties and add/fix all three keys: zkURL, clusterId, myid with non-empty values.
  2. Verify exact key names match ZkParamCfg's keys (e.g. zkURL=..., clusterId=..., myid=1) with no typos or extra whitespace.
  3. Ensure the file actually being loaded is the one on the runtime classpath, not a stale copy elsewhere.
  4. Set the three values via your deployment templating/env provisioning if the file is generated.

Example fix

// before (myid.properties)
#zkURL=
clusterId=cluster-1

// after
zkURL=127.0.0.1:2181
clusterId=cluster-1
myid=1
Defensive patterns

Strategy: validation

Validate before calling

Properties pros = new Properties();
try (InputStream is = getClass().getResourceAsStream("/zkcnf/myid.properties")) { pros.load(is); }
java.util.List<String> missing = java.util.stream.Stream.of("zkURL", "clusterId", "myid")
    .filter(k -> com.google.common.base.Strings.isNullOrEmpty(pros.getProperty(k)))
    .collect(java.util.stream.Collectors.toList());
if (!missing.isEmpty()) throw new IllegalStateException("myid.properties missing keys: " + missing);

Try / catch

try { ZkConfig.initZk(); } catch (RuntimeException e) { if (e.getMessage().contains("must not be null or empty")) { log.error("myid.properties is missing zkURL/clusterId/myid"); } throw e; }

Prevention

When it happens

Trigger: myid.properties loaded successfully but lacks any of: ZkParamCfg.ZK_CFG_URL (zkURL), ZkParamCfg.ZK_CFG_CLUSTERID (clusterId), ZkParamCfg.ZK_CFG_MYID (myid) keys, or the values are empty strings; thrown at ZkConfig.java:124 during ZkConfig startup.

Common situations: Fresh Mycat deployment where myid.properties was copied without filling in values, key names misspelled (case-sensitive properties keys), values commented out, or whitespace-only values left after editing.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/9db573157edd7104. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/config/loader/zkprocess/comm/ZkConfig.java:124

        try (InputStream configIS = ZkConfig.class.getResourceAsStream(ZK_CONFIG_FILE_NAME)) {
            if (configIS == null) {
                return null;
            }

            pros.load(configIS);
        } catch (IOException e) {
            LOGGER.error("ZkConfig LoadMyidPropersites error:", e);
            throw new RuntimeException("can't find myid properties file : " + ZK_CONFIG_FILE_NAME);
        }

        // validate
        String zkURL = pros.getProperty(ZkParamCfg.ZK_CFG_URL.getKey());
        String myid = pros.getProperty(ZkParamCfg.ZK_CFG_MYID.getKey());

        String clusterId = pros.getProperty(ZkParamCfg.ZK_CFG_CLUSTERID.getKey());

        if (Strings.isNullOrEmpty(clusterId) ||Strings.isNullOrEmpty(zkURL) || Strings.isNullOrEmpty(myid)) {
            throw new RuntimeException("clusterId and zkURL and myid must not be null or empty!");
        }
        return pros;

    }

    public static void main(String[] args) {
        String zk = ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_CLUSTERID);
        System.out.println(zk);
    }

}

View on GitHub (pinned to 65f8d8beb7)