alibaba/spring-ai-alibaba · error · IllegalArgumentException
Strategy type cannot be null or empty
Error message
Strategy type cannot be null or empty
What it means
registerStrategy derives the registry key from strategy.getStrategyType(); a null or blank type cannot serve as a lookup key, so IllegalArgumentException is thrown. The registry also rejects duplicate types with a separate error ('Strategy type ... is already registered').
Solutions
- Implement getStrategyType() to return a fixed non-blank constant (e.g. return "custom-conditional";)
- If the type is configurable, validate/trim it in the strategy constructor and fall back to a default
- Add a constructor assertion: Objects.requireNonNull(type); if (type.isBlank()) throw ...
Example fix
// before
@Override public String getStrategyType() { return configuredType; }
// after
@Override public String getStrategyType() {
return (configuredType == null || configuredType.isBlank())
? "custom" : configuredType.trim();
} Defensive patterns
Strategy: validation
Validate before calling
String t = strategy.getStrategyType(); if (t == null || t.trim().isEmpty()) throw new IllegalArgumentException(strategy.getClass().getName() + " returned blank strategy type");
Type guard
static boolean hasValidType(FlowGraphBuildingStrategy s) { String t = s.getStrategyType(); return t != null && !t.trim().isEmpty(); } Try / catch
try { registry.registerStrategy(strategy); } catch (IllegalArgumentException e) { throw new StrategyRegistrationException(e.getMessage(), e); } Prevention
- Return fixed constants from getStrategyType(), never config-derived values without defaults
- Assert the type in the strategy constructor
- Check for duplicate registrations too ('already registered' is a sibling error)
When it happens
Trigger: Registering a custom FlowGraphBuildingStrategy whose getStrategyType() returns null, "", or whitespace (e.g. a constant not initialized or a typo returning an empty string).
Common situations: Custom strategy class with getStrategyType() wired to an unset config property; copy-pasted strategy with forgotten type override; internationalization accidentally blanking the constant.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- At least one fallback model must be specified
- Condition keys cannot be null or empty
- Conditional flow requires at least one conditional agent…
- database cannot be null or blank
- dbType cannot be null or blank
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/30fdaa3f575b1577.
Report an issue: GitHub.
Appendix: source
Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/flow/strategy/FlowGraphBuildingStrategyRegistry.java:65
* @return the registry instance
*/
public static FlowGraphBuildingStrategyRegistry getInstance() {
return INSTANCE;
}
/**
* Registers a new graph building strategy (same instance returned each time).
* @param strategy the strategy to register
* @throws IllegalArgumentException if strategy is null or type is already registered
*/
public void registerStrategy(FlowGraphBuildingStrategy strategy) {
if (strategy == null) {
throw new IllegalArgumentException("Strategy cannot be null");
}
String type = strategy.getStrategyType();
if (type == null || type.trim().isEmpty()) {
throw new IllegalArgumentException("Strategy type cannot be null or empty");
}
if (strategyFactories.containsKey(type)) {
throw new IllegalArgumentException("Strategy type '" + type + "' is already registered");
}
strategyFactories.put(type, () -> strategy);
}
/**
* Registers a strategy factory. Each call to {@link #createStrategy(String)} or
* {@link #getStrategy(String)} will use the factory to obtain a strategy instance.
* @param type the strategy type
* @param factory the factory that creates strategy instances
* @throws IllegalArgumentException if type or factory is null, or type is already registered
*/
public void registerStrategy(String type, Supplier<FlowGraphBuildingStrategy> factory) {
if (type == null || type.trim().isEmpty()) {View on GitHub (pinned to f82da0b50f)