{"record":{"id":"f80493396612ca2e","repo":"apache/shenyu","slug":"datacenter-id-can-t-be-greater-than-d-or-less-than-0","errorCode":null,"errorMessage":"datacenter Id can't be greater than %d or less than 0","messagePattern":"datacenter Id can't be greater than (.+?) or less than 0","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"shenyu-common/src/main/java/org/apache/shenyu/common/utils/UUIDUtils.java","lineNumber":68,"sourceCode":"\n    private final long datacenterId;\n\n    private final long idepoch;\n\n    private long sequence = '0';\n\n    private long lastTimestamp = -1L;\n\n    private UUIDUtils() {\n        this(RANDOM.nextInt((int) MAX_WORKER_ID), RANDOM.nextInt((int) MAX_DATACENTER_ID), 1288834974657L);\n    }\n\n    private UUIDUtils(final long workerId, final long datacenterId, final long idepoch) {\n        if (workerId > MAX_WORKER_ID || workerId < 0) {\n            throw new IllegalArgumentException(String.format(\"worker Id can't be greater than %d or less than 0\", MAX_WORKER_ID));\n        }\n        if (datacenterId > MAX_DATACENTER_ID || datacenterId < 0) {\n            throw new IllegalArgumentException(String.format(\"datacenter Id can't be greater than %d or less than 0\", MAX_DATACENTER_ID));\n        }\n        this.workerId = workerId;\n        this.datacenterId = datacenterId;\n        this.idepoch = idepoch;\n    }\n\n    /**\n     * Gets instance.\n     *\n     * @return the instance\n     */\n    public static UUIDUtils getInstance() {\n        return ID_WORKER_UTILS;\n    }\n\n    private synchronized long nextId() {\n        long timestamp = timeGen();\n        if (timestamp < lastTimestamp) {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-common/src/main/java/org/apache/shenyu/common/utils/UUIDUtils.java#L50-L86","documentation":"Same Snowflake-style UUIDUtils constructor validates datacenterId within [0, MAX_DATACENTER_ID]. Values outside the range throw IllegalArgumentException 'datacenter Id can't be greater than %d or less than 0'.","triggerScenarios":"Constructing UUIDUtils with a datacenterId > MAX_DATACENTER_ID or < 0, e.g. from an out-of-range config value or faulty auto-assignment logic.","commonSituations":"Multi-datacenter deployments assigning ids beyond the configured maximum; config files with negative or oversized datacenter ids; refactored constants shrinking MAX_DATACENTER_ID while configs kept old values.","solutions":["Use a datacenterId within 0..MAX_DATACENTER_ID (see the constant in UUIDUtils).","Clamp or modulo the configured value into range before constructing.","Validate datacenter-id configuration at startup with a clear error message.","Keep datacenter-id assignments coordinated across environments."],"exampleFix":"// before\nUUIDUtils.create(1, 999); // datacenterId out of range\n// after\nlong dc = Math.floorMod(configuredDc, MAX_DATACENTER_ID + 1);\nUUIDUtils.create(1, dc);","handlingStrategy":"validation","validationCode":"if (datacenterId < 0 || datacenterId > MAX_DATACENTER_ID) throw new IllegalArgumentException(\"datacenterId must be in [0,\" + MAX_DATACENTER_ID + \"]\");","typeGuard":null,"tryCatchPattern":"try { idGen = new UUIDUtils(workerId, dcId, epoch); } catch (IllegalArgumentException e) { LOG.error(\"bad datacenter id\", e); idGen = new UUIDUtils(workerId, 0, epoch); }","preventionTips":["Validate datacenter-id config at startup","Clamp configured values into the allowed range","Coordinate datacenter ids across environments","Document MAX_DATACENTER_ID in deployment docs"],"tags":["snowflake","id-generation","argument-validation","config"],"backgroundTag":"value-out-of-range","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}