{"record":{"id":"9632b62ebceddb8d","repo":"alibaba/spring-ai-alibaba","slug":"skillregistry-cannot-be-null-9632b6","errorCode":null,"errorMessage":"SkillRegistry cannot be null","messagePattern":"SkillRegistry cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/hook/skills/ReadSkillTool.java","lineNumber":60,"sourceCode":"\tpublic static final String DESCRIPTION = \"\"\"\n\t\t\tReads the full content of a skill from the SkillRegistry.\n\t\t\tYou can use this tool to read the complete content of any skill by providing its name or path.\n\t\t\t\n\t\t\tUsage:\n\t\t\t- Provide either skill_name or skill_path\n\t\t\t- If both are provided, they must refer to the same skill\n\t\t\t- The tool returns the full content of the skill file (e.g., SKILL.md) without frontmatter\n\t\t\t- If the skill is not found, an error will be returned\n\t\t\t\n\t\t\tExample:\n\t\t\t- read_skill(\"pdf-extractor\")\n\t\t\t\"\"\";\n\tprivate static final Logger logger = LoggerFactory.getLogger(ReadSkillTool.class);\n\tprivate final SkillRegistry skillRegistry;\n\n\tpublic ReadSkillTool(SkillRegistry skillRegistry) {\n\t\tif (skillRegistry == null) {\n\t\t\tthrow new IllegalArgumentException(\"SkillRegistry cannot be null\");\n\t\t}\n\t\tthis.skillRegistry = skillRegistry;\n\t}\n\n\t/**\n\t * Create a ToolCallback for the read skill tool.\n\t */\n\tpublic static ToolCallback createReadSkillToolCallback(SkillRegistry skillRegistry, String description) {\n\t\treturn FunctionToolCallback.builder(READ_SKILL, new ReadSkillTool(skillRegistry))\n\t\t\t\t.description(description != null ? description : DESCRIPTION)\n\t\t\t\t.inputType(ReadSkillRequest.class)\n\t\t\t\t.build();\n\t}\n\n\t@Override\n\tpublic String apply(ReadSkillRequest request, ToolContext toolContext) {\n\t\ttry {\n\t\t\treturn readSkillContent(request);","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/hook/skills/ReadSkillTool.java#L42-L78","documentation":"ReadSkillTool's constructor rejects a null SkillRegistry. This tool delegates all skill-content reads to the registry, so without it the tool could never resolve a skill; the library validates at construction time and fails immediately.","triggerScenarios":"Calling new ReadSkillTool(null) or the factory createReadSkillToolCallback(skillRegistry, ...) (same null-arg pattern) with a null registry.","commonSituations":"Registry creation moved behind an optional feature flag that was off; a builder method returned null on error and the result was passed onward; bean wiring in Spring produced a null dependency.","solutions":["Instantiate the registry first: SkillRegistry registry = FileSystemSkillRegistry.builder().build(); then pass it to ReadSkillTool.","Only register the read-skill tool callback when a valid SkillRegistry exists.","Audit any wrapper that forwards a possibly-null registry into the ReadSkillTool factory."],"exampleFix":"// before\nReadSkillTool tool = new ReadSkillTool(null);\n// after\nSkillRegistry registry = FileSystemSkillRegistry.builder().build();\nReadSkillTool tool = new ReadSkillTool(registry);","handlingStrategy":"validation","validationCode":"if (skillRegistry == null) { throw new IllegalStateException(\"SkillRegistry must be created before ReadSkillTool\"); }\nReadSkillTool tool = new ReadSkillTool(skillRegistry);","typeGuard":"boolean isReady(SkillRegistry r) { return r != null; }","tryCatchPattern":"try { tool = new ReadSkillTool(registry); } catch (IllegalArgumentException e) { log.error(\"Skipped read-skill tool: {}\", e.getMessage()); }","preventionTips":["Create FileSystemSkillRegistry in a dedicated @Bean/initializer so it is never null.","Only register skill tools when the registry initialized successfully.","Never forward possibly-null builder results into tool factories."],"tags":["java","null-check","configuration"],"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"}