alibaba/spring-cloud-alibaba · error · IllegalStateException

namespaceName, flowRulesKey, and defaultFlowRuleValue must n

Error message

namespaceName, flowRulesKey, and defaultFlowRuleValue must not be null

What it means

Thrown by ApolloDataSourceFactoryBean.getObject() when any of namespaceName, flowRulesKey, or defaultFlowRuleValue is null. This FactoryBean creates an ApolloDataSource for Sentinel rule sourcing from Apollo configuration center. The check is a simple null-or guard — all three fields are @Nullable with no defaults, so all must be explicitly provided. This fires during Spring bean initialization when getObject() is called by the FactoryBean infrastructure.

Source

Thrown at spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/ApolloDataSourceFactoryBean.java:44

 * A {@link FactoryBean} for creating {@link ApolloDataSource} instance.
 *
 * @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
 * @see ApolloDataSource
 */
public class ApolloDataSourceFactoryBean implements FactoryBean<ApolloDataSource> {

	private @Nullable String namespaceName;

	private @Nullable String flowRulesKey;

	private @Nullable String defaultFlowRuleValue;

	private @Nullable Converter converter;

	@Override
	public ApolloDataSource getObject() throws Exception {
		if (namespaceName == null || flowRulesKey == null || defaultFlowRuleValue == null) {
			throw new IllegalStateException("namespaceName, flowRulesKey, and defaultFlowRuleValue must not be null");
		}
		return new ApolloDataSource(namespaceName, flowRulesKey, defaultFlowRuleValue,
				converter);
	}

	@Override
	public Class<?> getObjectType() {
		return ApolloDataSource.class;
	}

	public @Nullable String getNamespaceName() {
		return namespaceName;
	}

	public void setNamespaceName(@Nullable String namespaceName) {
		this.namespaceName = namespaceName;
	}

View on GitHub (pinned to 115d590110)

Solutions

  1. Provide all three properties: spring.cloud.sentinel.datasource.<name>.apollo.namespace-name, flow-rules-key, and default-flow-rule-value.
  2. Verify the namespaceName matches an existing Apollo namespace and flowRulesKey matches a key within that namespace.
  3. Set defaultFlowRuleValue to a valid empty-rule JSON array '[]' if no default fallback rules are needed.

Example fix

# before (broken — defaultFlowRuleValue missing)
spring:
  cloud:
    sentinel:
      datasource:
        ds1:
          apollo:
            namespace-name: application
            flow-rules-key: sentinel.flow.rules

# after (fixed)
spring:
  cloud:
    sentinel:
      datasource:
        ds1:
          apollo:
            namespace-name: application
            flow-rules-key: sentinel.flow.rules
            default-flow-rule-value: "[]"
Defensive patterns

Strategy: validation

Validate before calling

// Validate Apollo datasource properties before FactoryBean.getObject()
ApolloDataSourceFactoryBean fb = new ApolloDataSourceFactoryBean();
if (namespaceName == null || flowRulesKey == null || defaultFlowRuleValue == null) {
    throw new IllegalStateException(
        "ApolloDataSource requires namespaceName, flowRulesKey, and defaultFlowRuleValue");
}
fb.setNamespaceName(namespaceName);
fb.setFlowRulesKey(flowRulesKey);
fb.setDefaultFlowRuleValue(defaultFlowRuleValue);
fb.setConverter(converter);
fb.getObject();

Prevention

When it happens

Trigger: Configuring a Sentinel datasource of type 'apollo' and omitting one or more of the three required properties: namespaceName, flowRulesKey, or defaultFlowRuleValue. The FactoryBean fields are populated from spring.cloud.sentinel.datasource.<name>.apollo.* properties; if any is absent, the null check triggers.

Common situations: 1) Developer provides namespaceName and flowRulesKey but forgets defaultFlowRuleValue. 2) Apollo namespace or key was renamed but application config not updated. 3) Migration from another datasource type (e.g., file) where defaultFlowRuleValue was not needed and is overlooked.

Related errors


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/6f93ef6659a7680f. Report an issue: GitHub.