{"record":{"id":"39edc406aeafb989","repo":"alibaba/spring-ai-alibaba","slug":"template-cannot-be-null","errorCode":null,"errorMessage":"Template cannot be null","messagePattern":"Template cannot 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/node/TemplateTransformNode.java","lineNumber":379,"sourceCode":"\t\treturn defaultValue;\n\t}\n\n\tpublic static Builder builder() {\n\t\treturn new Builder();\n\t}\n\n\t/**\n\t * Builder class for TemplateTransformNode\n\t */\n\tpublic static class Builder {\n\n\t\tprivate String template;\n\n\t\tprivate String outputKey;\n\n\t\tpublic Builder template(String template) {\n\t\t\tif (template == null) {\n\t\t\t\tthrow new IllegalArgumentException(\"Template cannot be null\");\n\t\t\t}\n\t\t\tthis.template = template;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic Builder outputKey(String outputKey) {\n\t\t\tthis.outputKey = outputKey;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic TemplateTransformNode build() {\n\t\t\tif (template == null) {\n\t\t\t\tthrow new IllegalArgumentException(\"Template cannot be null\");\n\t\t\t}\n\t\t\treturn new TemplateTransformNode(template, outputKey);\n\t\t}\n\n\t}","sourceCodeStart":361,"sourceCodeEnd":397,"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/TemplateTransformNode.java#L361-L397","documentation":"TemplateTransformNode.Builder.template(String) rejects null templates with IllegalArgumentException('Template cannot be null'). A null template would make the node's text transformation impossible, so it is validated eagerly at builder time.","triggerScenarios":"Calling builder.template(null) directly, or passing a variable/method result that resolves to null (e.g. missing config property or unreturned map lookup).","commonSituations":"Template loaded from config/properties that was not set; Map.get(\"template\") returning null; refactoring that renamed the template field.","solutions":["Pass a non-null template string to template(...)","Verify the config/property source actually provides the template value","Add a null/blank check with a clear message before building in caller code"],"exampleFix":"// before\nbuilder.template(config.get(\"template\")); // may be null\n// after\nString tpl = config.get(\"template\");\nif (tpl == null) { throw new IllegalStateException(\"template config missing\"); }\nbuilder.template(tpl);","handlingStrategy":"validation","validationCode":"if (tpl == null || tpl.isBlank()) { throw new IllegalStateException(\"template must be provided\"); }\nbuilder.template(tpl);","typeGuard":"static boolean hasTemplate(Map<String,String> cfg) { return StringUtils.hasText(cfg.get(\"template\")); }","tryCatchPattern":"try { node = builder.template(tpl)...build(); } catch (IllegalArgumentException e) { log.error(\"template null\", e); }","preventionTips":["Load templates from config with explicit defaults","Assert template presence at application startup","Avoid Map.get results passed directly into builders without null checks"],"tags":["builder-validation","null-argument"],"backgroundTag":"null-argument","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}