{"record":{"id":"6847ee80425bf9fe","repo":"alibaba/COLA","slug":"alphabet-must-contain-between-1-and-255-symbols","errorCode":null,"errorMessage":"alphabet must contain between 1 and 255 symbols.","messagePattern":"alphabet must contain between 1 and 255 symbols\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"cola-components/cola-component-job/src/main/java/com/alibaba/cola/job/UuidGenerator.java","lineNumber":91,"sourceCode":"                    StringBuilder idBuilder = new StringBuilder();\n\n                    while(true) {\n                        byte[] bytes = new byte[step];\n                        random.nextBytes(bytes);\n\n                        for(int i = 0; i < step; ++i) {\n                            int alphabetIndex = bytes[i] & mask;\n                            if (alphabetIndex < alphabet.length) {\n                                idBuilder.append(alphabet[alphabetIndex]);\n                                if (idBuilder.length() == size) {\n                                    return idBuilder.toString();\n                                }\n                            }\n                        }\n                    }\n                }\n            } else {\n                throw new IllegalArgumentException(\"alphabet must contain between 1 and 255 symbols.\");\n            }\n        }\n    }\n}\n\n","sourceCodeStart":73,"sourceCodeEnd":97,"githubUrl":"https://github.com/alibaba/COLA/blob/352e1a867538d9cd40e1b11e4028fa652fc97557/cola-components/cola-component-job/src/main/java/com/alibaba/cola/job/UuidGenerator.java#L73-L97","documentation":"Argument-validation guard inside NanoIdUtils.randomNanoId: the supplied alphabet has more than 255 unique symbols (or is empty after uniqueness filtering). The generator picks characters by masking a random byte to at most 255 candidate slots, so an alphabet larger than 255 symbols cannot be indexed reliably; this guard rejects it before any id-building loop runs. The input at fault is the caller-provided char[] alphabet.","triggerScenarios":"Calling randomNanoId with an empty char[] (length 0) or a char[] of 256+ symbols.","commonSituations":"Passing a Unicode-heavy custom alphabet with too many symbols; building the alphabet from an empty config string; concatenating alphabets until exceeding 255.","solutions":["Provide an alphabet of 1-255 unique symbols","Trim a too-large alphabet to a safe subset (e.g. 62 alphanumeric chars)","Handle empty configured alphabet by falling back to DEFAULT_ALPHABET"],"exampleFix":"// before\nchar[] alphabet = configAlphabet.toCharArray(); // may be empty or >255\n// after\nchar[] alphabet = (configAlphabet == null || configAlphabet.isEmpty() || configAlphabet.length() > 255)\n        ? DEFAULT_ALPHABET : configAlphabet.toCharArray();","handlingStrategy":"validation","validationCode":"if (alphabet == null || alphabet.length < 1 || alphabet.length > 255) {\n    throw new IllegalArgumentException(\"alphabet must contain between 1 and 255 symbols\");\n}","typeGuard":"boolean isValidAlphabet(char[] alphabet) {\n    return alphabet != null && alphabet.length >= 1 && alphabet.length <= 255;\n}","tryCatchPattern":"try {\n    id = UuidGenerator.randomNanoId(random, alphabet, size);\n} catch (IllegalArgumentException e) {\n    log.warn(\"Invalid alphabet, using default: {}\", e.getMessage());\n    id = UuidGenerator.randomNanoId(random, DEFAULT_ALPHABET, size);\n}","preventionTips":["Keep alphabets within 1-255 unique chars","Check for null/empty alphabets built from config at startup","Write a test for custom alphabet configs"],"tags":["java","uuid","argument-out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"352e1a867538d9cd40e1b11e4028fa652fc97557","analyzedAt":"2026-09-08T00:46:23.972Z","contentChangedAt":"2026-09-08T00:46:23.972Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}