{"record":{"id":"9149827b86bd4c38","repo":"jeecgboot/JeecgBoot","slug":"error-914982","errorCode":null,"errorMessage":"编码长度必须能被固定位数整除","messagePattern":"编码长度必须能被固定位数整除","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java","lineNumber":1943,"sourceCode":"        }\n        return \"\";\n    }\n    \n    /**\n     * 获取编码及其所有上级编码\n     * \n     * @param code 完整编码，如 \"A01A01A01\"\n     * @param fixedLength 固定位数，如 3\n     * @return 包含所有上级编码的列表，如 ['A01','A01A01','A01A01A01']\n     */\n    public List<String> getCodeHierarchy(String code, int fixedLength) {\n        List<String> hierarchy = new ArrayList<>();\n        if (code == null || code.isEmpty() || fixedLength <= 0) {\n            return hierarchy;\n        }\n        // 检查编码长度是否能被固定位数整除\n        if (code.length() % fixedLength != 0) {\n            throw new IllegalArgumentException(\"编码长度必须能被固定位数整除\");\n        }\n        // 按固定位数分割并生成所有上级编码\n        for (int i = fixedLength; i <= code.length(); i += fixedLength) {\n            hierarchy.add(code.substring(0, i));\n        }\n        return hierarchy;\n    }\n\n    /**\n     * 根据多个部门id删除主岗位和兼职岗位\n     * \n     * @param idList\n     */\n    private void deleteDepartPostByDepIds(List<String> idList) {\n        //更新用户主岗位位空，使用LambdaUpdateWrapper，避免为空时受全局 updateStrategy 影响导致误更新\n        LambdaUpdateWrapper<SysUser> userQuery = new LambdaUpdateWrapper<>();\n        userQuery.in(SysUser::getMainDepPostId, idList);\n        userQuery.set(SysUser::getMainDepPostId, null);","sourceCodeStart":1925,"sourceCodeEnd":1961,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java#L1925-L1961","documentation":"Thrown by SysDepartServiceImpl.getCodeHierarchy when code.length() % fixedLength != 0. This is a standard IllegalArgumentException (unchecked) used to enforce that department org-codes follow a fixed-length segment convention (e.g., 'A01A01A01' with fixedLength=3). The method builds a hierarchy of parent codes by splitting at fixedLength boundaries, so a non-divisible length would produce malformed partial codes.","triggerScenarios":"Passing an org-code whose length is not a multiple of the expected segment size — for example code='A01B' with fixedLength=3, or a code with trailing/leading whitespace that throws off the length, or a fixedLength of 0 (though that's guarded earlier and returns empty). Also triggered when mixing different department coding schemes.","commonSituations":"Department org-code format mismatch after a data migration or schema change; a manually-entered org-code that doesn't follow the A01A01A01 pattern; calling getCodeHierarchy with a fixedLength derived from config that doesn't match the actual code generation scheme.","solutions":["Confirm the org-code format matches the expected fixedLength segment convention (e.g., each level is exactly N characters).","Trim and validate the code before calling: ensure code.length() % fixedLength == 0.","If mixed code formats are expected, split the method into separate code paths rather than forcing one fixedLength.","Check the department code-generation configuration to verify segment length matches the value passed as fixedLength."],"exampleFix":"// before\nList<String> h = service.getCodeHierarchy(\"A01B\", 3);\n// throws IllegalArgumentException: 编码长度必须能被固定位数整除\n\n// after — validate before calling\nString code = \"A01B\".trim();\nint fixedLength = 3;\nif (code.isEmpty() || code.length() % fixedLength != 0) {\n    log.warn(\"Invalid org code format: {} for fixedLength {}\", code, fixedLength);\n    return Collections.emptyList();\n}\nList<String> h = service.getCodeHierarchy(code, fixedLength);","handlingStrategy":"validation","validationCode":"public boolean isValidOrgCodeFormat(String code, int fixedLength) {\n    if (code == null || code.isEmpty() || fixedLength <= 0) return false;\n    return code.length() % fixedLength == 0;\n}\n\n// Before calling:\nif (!isValidOrgCodeFormat(code, fixedLength)) {\n    log.warn(\"Invalid org code format: {} for fixedLength {}\", code, fixedLength);\n    return Collections.emptyList();\n}","typeGuard":"public boolean isCodeDivisible(String code, int fixedLength) {\n    return code != null && !code.isEmpty() && fixedLength > 0\n        && code.length() % fixedLength == 0;\n}","tryCatchPattern":"try {\n    List<String> hierarchy = service.getCodeHierarchy(code, fixedLength);\n} catch (IllegalArgumentException e) {\n    log.warn(\"Org code hierarchy failed: code={}, fixedLength={}\", code, fixedLength);\n    return Collections.emptyList();\n}","preventionTips":["Validate code.length() % fixedLength == 0 before calling getCodeHierarchy.","Ensure org-code generation follows a consistent fixed-length segment scheme.","Trim whitespace from codes before processing."],"tags":["jeecg-boot","org-code","validation","illegal-argument"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}