{"record":{"id":"1517703e0c061556","repo":"alibaba/spring-ai-alibaba","slug":"skillregistry-cannot-be-null-151770","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/SearchSkillsTool.java","lineNumber":51,"sourceCode":" */\npublic class SearchSkillsTool implements BiFunction<SearchSkillsTool.SearchSkillsRequest, ToolContext, String> {\n\n\tpublic static final String SEARCH_SKILLS = \"search_skills\";\n\n\tpublic static final String DESCRIPTION = \"\"\"\n\t\t\tSearches the current SkillRegistry by skill name, description, or skill path.\n\t\t\t\n\t\t\tUsage:\n\t\t\t- Provide a query to search the locally registered skills\n\t\t\t- Matching is performed against name, description, and path\n\t\t\t- Returns matching skills with their descriptions and paths\n\t\t\t\"\"\";\n\n\tprivate final SkillRegistry skillRegistry;\n\n\tpublic SearchSkillsTool(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\tpublic static ToolCallback createSearchSkillsToolCallback(SkillRegistry skillRegistry, String description) {\n\t\treturn FunctionToolCallback.builder(SEARCH_SKILLS, new SearchSkillsTool(skillRegistry))\n\t\t\t\t.description(description != null ? description : DESCRIPTION)\n\t\t\t\t.inputType(SearchSkillsRequest.class)\n\t\t\t\t.build();\n\t}\n\n\t@Override\n\tpublic String apply(SearchSkillsRequest request, ToolContext toolContext) {\n\t\tString query = request != null ? request.query : null;\n\t\tList<SkillMetadata> skills = skillRegistry.search(query);\n\t\tif (skills.isEmpty()) {\n\t\t\treturn \"No skills found.\";\n\t\t}","sourceCodeStart":33,"sourceCodeEnd":69,"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/SearchSkillsTool.java#L33-L69","documentation":"SearchSkillsTool's constructor rejects a null SkillRegistry. Searching skills is entirely registry-backed, so the library validates the dependency at construction and fails fast rather than throwing NPEs on first use.","triggerScenarios":"Calling new SearchSkillsTool(null) or createSearchSkillsToolCallback(skillRegistry, description) with a null registry.","commonSituations":"Optional skill-directory loading skipped, yielding null; refactored wiring that dropped registry initialization; DI container returning null because the registry bean was not configured.","solutions":["Build the registry before the tool: SkillRegistry registry = FileSystemSkillRegistry.builder().build();","Conditionally register the search-skills tool only when a non-null registry exists.","Check the call site of createSearchSkillsToolCallback and ensure it forwards a real registry."],"exampleFix":"// before\nToolCallback cb = SearchSkillsTool.createSearchSkillsToolCallback(null, \"Search skills\");\n// after\nSkillRegistry registry = FileSystemSkillRegistry.builder().build();\nToolCallback cb = SearchSkillsTool.createSearchSkillsToolCallback(registry, \"Search skills\");","handlingStrategy":"validation","validationCode":"if (registry == null) { throw new IllegalStateException(\"Create SkillRegistry before SearchSkillsTool\"); }\nSearchSkillsTool tool = new SearchSkillsTool(registry);","typeGuard":"boolean registryPresent(SkillRegistry r) { return r != null; }","tryCatchPattern":"try { tool = new SearchSkillsTool(registry); } catch (IllegalArgumentException e) { log.error(\"Registry required: {}\", e.getMessage()); }","preventionTips":["Centralize SkillRegistry construction so all skill tools share one non-null instance.","Gate skill-tool registration on successful registry initialization.","Fail fast at startup if the skills directory cannot be loaded."],"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"}