{"record":{"id":"6b77f9e5172a4304","repo":"iflytek/astron-agent","slug":"response-failed","errorCode":"RESPONSE_FAILED","errorMessage":"Related enumeration class not found","messagePattern":"Related enumeration class not found","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/entity/enumVo/DBTableEnvEnum.java","lineNumber":39,"sourceCode":"        this.code = code;\n        this.value = value;\n    }\n\n    public Integer getCode() {\n        return code;\n    }\n\n    public String getValue() {\n        return value;\n    }\n\n    public static String getByCode(Integer code) {\n        for (DBTableEnvEnum envEnum : DBTableEnvEnum.values()) {\n            if (Objects.equals(envEnum.getCode(), code)) {\n                return envEnum.getValue();\n            }\n        }\n        throw new BusinessException(ResponseEnum.RESPONSE_FAILED, \"Related enumeration class not found\");\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":42,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/entity/enumVo/DBTableEnvEnum.java#L21-L42","documentation":"DBTableEnvEnum.getByCode(code) linearly searches the enum's values for a matching Integer code and returns its string value. When no constant matches, it throws BusinessException(ResponseEnum.RESPONSE_FAILED, \"Related enumeration class not found\"). This is a lookup-miss guard translating a raw DB integer code into a human-readable environment name.","triggerScenarios":"Calling DBTableEnvEnum.getByCode with an Integer that is not one of the enum's defined codes (e.g. a new environment value inserted into a DB table without adding the corresponding enum constant).","commonSituations":"A database migration or another service wrote a new env code the enum does not know; a typo'd or null-shifted code passed from a form; enum updated in one module but the calling code uses stale codes after a version upgrade.","solutions":["Log the offending code value and add a matching DBTableEnvEnum constant for it.","Verify the code stored in the DB table is valid; fix bad rows with an UPDATE if they are corrupt.","If the code comes from user input, validate it against the enum's known codes before calling getByCode.","As hardening, return an Optional or default value instead of throwing for unknown codes if unmapped values are tolerable."],"exampleFix":"// before\nthrow new BusinessException(ResponseEnum.RESPONSE_FAILED, \"Related enumeration class not found\");\n\n// after\nDBTableEnvEnum matched = Arrays.stream(values())\n        .filter(e -> Objects.equals(e.getCode(), code)).findFirst().orElse(null);\nif (matched == null) {\n    log.warn(\"Unknown DBTableEnvEnum code={}\", code);\n    return \"UNKNOWN\";\n}\nreturn matched.getValue();","handlingStrategy":"validation","validationCode":"final Set<Integer> known = Arrays.stream(DBTableEnvEnum.values())\n        .map(DBTableEnvEnum::getCode).collect(Collectors.toSet());\nif (!known.contains(code)) {\n    log.warn(\"Skipping unknown env code={}\", code);\n}","typeGuard":"boolean isKnownEnvCode(Integer code) {\n    return Arrays.stream(DBTableEnvEnum.values())\n            .anyMatch(e -> Objects.equals(e.getCode(), code));\n}","tryCatchPattern":"try {\n    String env = DBTableEnvEnum.getByCode(code);\n} catch (BusinessException e) {\n    log.warn(\"Unmapped env code={}, using default\", code);\n    String env = DEFAULT_ENV;\n}","preventionTips":["Add a new enum constant whenever a new env code is introduced in DB data or migrations.","Validate user-supplied env codes against the enum before persistence.","Keep enum definitions synchronized across modules after version upgrades."],"tags":["enum","lookup","invalid-value","java"],"backgroundTag":"invalid-enum-value","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}