{"record":{"id":"a62eaec29b57d3ac","repo":"alibaba/spring-ai-alibaba","slug":"code-must-not-be-null-a62eae","errorCode":null,"errorMessage":"Code must not be null","messagePattern":"Code must not be null","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/utils/FileUtils.java","lineNumber":43,"sourceCode":"import java.nio.file.Path;\nimport java.nio.file.StandardCopyOption;\nimport java.util.Collections;\nimport java.util.Enumeration;\n\n/**\n * @author HeYQ\n * @since 2024-11-28 11:47\n */\npublic class FileUtils {\n\n\tprivate FileUtils() {\n\t\tthrow new IllegalStateException(\"Utility class\");\n\t}\n\n\tpublic static void writeCodeToFile(String workDir, String filename, String code) {\n\t\ttry {\n\t\t\tif (code == null) {\n\t\t\t\tthrow new IllegalArgumentException(\"Code must not be null\");\n\t\t\t}\n\t\t\tPath filepath = Path.of(workDir, filename);\n\t\t\t// ensure the parent directory exists\n\t\t\tPath fileDir = filepath.getParent();\n\t\t\tif (fileDir != null && !Files.exists(fileDir)) {\n\t\t\t\tFiles.createDirectories(fileDir);\n\t\t\t}\n\t\t\t// write the code to the file\n\t\t\tFiles.writeString(filepath, code);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\t/**\n\t * Deletes the file specified by the filename from the provided working directory.\n\t * @param workDir The working directory where the file to be deleted is located.","sourceCodeStart":25,"sourceCodeEnd":61,"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/utils/FileUtils.java#L25-L61","documentation":"FileUtils.writeCodeToFile throws IllegalArgumentException('Code must not be null') when the code parameter is null, before writing the file. It ensures a valid source string exists prior to creating directories and writing the temp code file.","triggerScenarios":"Calling writeCodeToFile(workDir, filename, null) — e.g. the code block was never populated from the LLM response, or a config map lookup returned null for the code key.","commonSituations":"LLM response parse yielded no code body; upstream null propagation from an empty Optional/map.get; wiring a code executor node without setting its input mapping.","solutions":["Validate code is non-null (and ideally non-blank) before calling writeCodeToFile.","Trace upstream why the code block is empty — check LLM response parsing and node input mappings.","Substitute a default or skip execution gracefully when no code is present.","Catch IllegalArgumentException and surface a clear error to the workflow."],"exampleFix":"// before\nFileUtils.writeCodeToFile(workDir, filename, block.getCode()); // throws if null\n// after\nString code = block.getCode();\nif (code == null || code.isBlank()) {\n    throw new IllegalStateException(\"Code block has no body\");\n}\nFileUtils.writeCodeToFile(workDir, filename, code);","handlingStrategy":"validation","validationCode":"if (code == null || code.isBlank()) {\n    throw new IllegalArgumentException(\"Cannot write code file: code is null or blank\");\n}","typeGuard":"boolean hasCodeBody(String code) {\n    return code != null && !code.isBlank();\n}","tryCatchPattern":"try {\n    FileUtils.writeCodeToFile(workDir, filename, code);\n} catch (IllegalArgumentException e) {\n    log.error(\"No code body to write — check upstream node output\", e);\n    throw e;\n}","preventionTips":["Validate code blocks right after parsing the LLM response","Use Optional or explicit defaults so null code never propagates to file writes","Fail fast at the workflow input boundary when a code block is empty"],"tags":["null-check","file-write","argument-validation"],"backgroundTag":"null-argument","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"}