alibaba/Sentinel · error · IllegalArgumentException
parser can't be null
Error message
parser can't be null
What it means
AbstractDataSource is the base of all Sentinel readable data sources (file, Nacos, Apollo, Consul, zk, etc.). It needs a Converter<S,T> to turn raw source data into rule objects and throws IllegalArgumentException if the parser is null — without it loadConfig(conf) could not convert anything.
Source
Thrown at sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/AbstractDataSource.java:36
import com.alibaba.csp.sentinel.property.DynamicSentinelProperty;
import com.alibaba.csp.sentinel.property.SentinelProperty;
/**
* The abstract readable data source provides basic functionality for loading and parsing config.
*
* @param <S> source data type
* @param <T> target data type
* @author Carpenter Lee
* @author Eric Zhao
*/
public abstract class AbstractDataSource<S, T> implements ReadableDataSource<S, T> {
protected final Converter<S, T> parser;
protected final SentinelProperty<T> property;
public AbstractDataSource(Converter<S, T> parser) {
if (parser == null) {
throw new IllegalArgumentException("parser can't be null");
}
this.parser = parser;
this.property = new DynamicSentinelProperty<T>();
}
@Override
public T loadConfig() throws Exception {
return loadConfig(readSource());
}
public T loadConfig(S conf) throws Exception {
T value = parser.convert(conf);
return value;
}
@Override
public SentinelProperty<T> getProperty() {
return property;View on GitHub (pinned to a3f40ba8e9)
Solutions
- Supply a real Converter, typically converter = s -> JSON.parseObject(s, new TypeReference<List<FlowRule>>() {}).
- If the converter comes from a factory/helper, check it cannot return null and fail there with a clearer error.
- Remove null 'placeholder' converters from scaffolding code before shipping.
Example fix
// before
ReadableDataSource<String, List<FlowRule>> ds =
new FileRefreshableDataSource<>(file, null);
// after
Converter<String, List<FlowRule>> parser = s ->
JSON.parseObject(s, new TypeReference<List<FlowRule>>() {});
ReadableDataSource<String, List<FlowRule>> ds =
new FileRefreshableDataSource<>(file, parser); Defensive patterns
Strategy: validation
Validate before calling
Converter<String, List<FlowRule>> parser = s ->
JSON.parseObject(s, new TypeReference<List<FlowRule>>() {});
Objects.requireNonNull(parser, "config parser is required");
new FileRefreshableDataSource<>(file, parser, charset); Type guard
boolean hasParser(Converter<?, ?> parser) {
return parser != null;
} Prevention
- Create the converter inline at the construction site — never thread an uninitialized field into a datasource.
- Centralize converter creation in one factory per rule type.
When it happens
Trigger: Constructing any datasource subclass with a null Converter, e.g. new FileRefreshableDataSource(file, null) or new NacosDataSource(properties, groupId, dataId, null).
Common situations: Passing a converter variable that was never initialized; using a JSON converter factory method that returned null; copy-pasting datasource examples while omitting the converter lambda.
Related errors
- File can't be null or a directory
- charset can't be null
- Bad file
- Config encoder cannot be null
- Charset cannot be null
AI-assisted analysis of alibaba/Sentinel@a3f40ba8e9 (2026-08-14).
Data as JSON: /api/errors/39eacb4fca3bfe16.
Report an issue: GitHub.