{"record":{"id":"fdb748345c336d1b","repo":"alibaba/spring-ai-alibaba","slug":"invalid-code-language-provided","errorCode":null,"errorMessage":"Invalid code language provided","messagePattern":"Invalid code language provided","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/node/code/entity/CodeLanguage.java","lineNumber":39,"sourceCode":" */\npublic enum CodeLanguage {\n\n\tPYTHON3(\"python3\"), PYTHON(\"python\"), JINJA2(\"jinja2\"), JAVASCRIPT(\"javascript\"), JAVA(\"java\");\n\n\tprivate final String value;\n\n\tCodeLanguage(String value) {\n\t\tthis.value = value;\n\t}\n\n\tpublic String getValue() {\n\t\treturn value;\n\t}\n\n\t// Optionally, you can add a method to find an enum constant by its string value\n\tpublic static CodeLanguage fromValue(String value) {\n\t\tif (value == null || value.trim().isEmpty()) {\n\t\t\tthrow new IllegalArgumentException(\"Invalid code language provided\");\n\t\t}\n\t\tfor (CodeLanguage lang : values()) {\n\t\t\tif (lang.getValue().equalsIgnoreCase(value)) {\n\t\t\t\treturn lang;\n\t\t\t}\n\t\t}\n\t\tthrow new IllegalArgumentException(\"No enum constant \" + CodeLanguage.class.getName() + \".\" + value);\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t\treturn this.value;\n\t}\n\n}\n","sourceCodeStart":21,"sourceCodeEnd":55,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/node/code/entity/CodeLanguage.java#L21-L55","documentation":"CodeLanguage.fromValue throws IllegalArgumentException('Invalid code language provided') when the input string is null or blank. It is the enum's guard clause before attempting case-insensitive matching against known language values.","triggerScenarios":"Calling CodeLanguage.fromValue(null) or fromValue(\"  \") — typically when a config property or LLM-supplied code block has no language set and the null check at the call site was skipped.","commonSituations":"YAML/properties config where the language key exists but is empty; LLM code fence without a language tag (```) parsed into an empty string; forgetting to default the language before conversion.","solutions":["Ensure the language string is set and non-blank before calling fromValue.","Provide a sensible default (e.g. 'python') when language is absent.","Catch IllegalArgumentException and report which config field was empty."],"exampleFix":"// before\nCodeLanguage lang = CodeLanguage.fromValue(config.getLanguage()); // throws if blank\n// after\nString language = config.getLanguage();\nif (language == null || language.isBlank()) language = \"python\";\nCodeLanguage lang = CodeLanguage.fromValue(language);","handlingStrategy":"validation","validationCode":"String lang = rawLanguage == null ? \"python\" : rawLanguage.trim();\nif (lang.isEmpty()) lang = \"python\";","typeGuard":"boolean isNonBlankLanguage(String lang) {\n    return lang != null && !lang.trim().isEmpty();\n}","tryCatchPattern":"try {\n    return CodeLanguage.fromValue(rawLanguage);\n} catch (IllegalArgumentException e) {\n    log.warn(\"Blank/invalid language '{}', defaulting to PYTHON\", rawLanguage);\n    return CodeLanguage.PYTHON;\n}","preventionTips":["Default the language field in config classes so it is never null","Strip code fences carefully when parsing LLM output so the tag is captured","Validate config at startup instead of at execution time"],"tags":["enum","null-check","empty-string","code-execution"],"backgroundTag":"empty-required-field","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}