alibaba/spring-ai-alibaba · error · IllegalArgumentException

SkillRegistry cannot be null

Error message

SkillRegistry cannot be null

What it means

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.

Source

Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/hook/skills/ReadSkillTool.java:60

	public static final String DESCRIPTION = """
			Reads the full content of a skill from the SkillRegistry.
			You can use this tool to read the complete content of any skill by providing its name or path.
			
			Usage:
			- Provide either skill_name or skill_path
			- If both are provided, they must refer to the same skill
			- The tool returns the full content of the skill file (e.g., SKILL.md) without frontmatter
			- If the skill is not found, an error will be returned
			
			Example:
			- read_skill("pdf-extractor")
			""";
	private static final Logger logger = LoggerFactory.getLogger(ReadSkillTool.class);
	private final SkillRegistry skillRegistry;

	public ReadSkillTool(SkillRegistry skillRegistry) {
		if (skillRegistry == null) {
			throw new IllegalArgumentException("SkillRegistry cannot be null");
		}
		this.skillRegistry = skillRegistry;
	}

	/**
	 * Create a ToolCallback for the read skill tool.
	 */
	public static ToolCallback createReadSkillToolCallback(SkillRegistry skillRegistry, String description) {
		return FunctionToolCallback.builder(READ_SKILL, new ReadSkillTool(skillRegistry))
				.description(description != null ? description : DESCRIPTION)
				.inputType(ReadSkillRequest.class)
				.build();
	}

	@Override
	public String apply(ReadSkillRequest request, ToolContext toolContext) {
		try {
			return readSkillContent(request);

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Instantiate the registry first: SkillRegistry registry = FileSystemSkillRegistry.builder().build(); then pass it to ReadSkillTool.
  2. Only register the read-skill tool callback when a valid SkillRegistry exists.
  3. Audit any wrapper that forwards a possibly-null registry into the ReadSkillTool factory.

Example fix

// before
ReadSkillTool tool = new ReadSkillTool(null);
// after
SkillRegistry registry = FileSystemSkillRegistry.builder().build();
ReadSkillTool tool = new ReadSkillTool(registry);
Defensive patterns

Strategy: validation

Validate before calling

if (skillRegistry == null) { throw new IllegalStateException("SkillRegistry must be created before ReadSkillTool"); }
ReadSkillTool tool = new ReadSkillTool(skillRegistry);

Type guard

boolean isReady(SkillRegistry r) { return r != null; }

Try / catch

try { tool = new ReadSkillTool(registry); } catch (IllegalArgumentException e) { log.error("Skipped read-skill tool: {}", e.getMessage()); }

Prevention

When it happens

Trigger: Calling new ReadSkillTool(null) or the factory createReadSkillToolCallback(skillRegistry, ...) (same null-arg pattern) with a null registry.

Common situations: 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.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/9632b62ebceddb8d. Report an issue: GitHub.