apache/hadoop · error · ServiceStateException
Cannot initialize service ${name}: null configuration
Error message
Cannot initialize service ${name}: null configuration What it means
AbstractService implements the Hadoop service lifecycle (NOTINITED -> INITED -> STARTED -> STOPPED). init(Configuration) is the first transition and immediately rejects a null Configuration with ServiceStateException "Cannot initialize service <name>: null configuration" - a service cannot be initialized without configuration, and passing null is always a caller bug.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/service/AbstractService.java:155
* needs to override that initial setting -for example replacing
* it with a new subclass of {@link Configuration}
* @param conf new configuration.
*/
protected void setConfig(Configuration conf) {
this.config = conf;
}
/**
* {@inheritDoc}
* This invokes {@link #serviceInit}
* @param conf the configuration of the service. This must not be null
* @throws ServiceStateException if the configuration was null,
* the state change not permitted, or something else went wrong
*/
@Override
public void init(Configuration conf) {
if (conf == null) {
throw new ServiceStateException("Cannot initialize service "
+ getName() + ": null configuration");
}
if (isInState(STATE.INITED)) {
return;
}
synchronized (stateChangeLock) {
if (enterState(STATE.INITED) != STATE.INITED) {
setConfig(conf);
try {
serviceInit(config);
if (isInState(STATE.INITED)) {
//if the service ended up here during init,
//notify the listeners
notifyListeners();
}
} catch (Exception e) {
noteFailure(e);
ServiceOperations.stopQuietly(LOG, this);View on GitHub (pinned to 2add963021)
Solutions
- Pass a real Configuration - typically the propagated one from the parent/composite, or new Configuration() for defaults.
- Add Objects.requireNonNull(conf) at the construction site so the bug surfaces with a useful stack trace.
- If conf is genuinely undetermined at that point, restructure so init() is called after config resolution.
Example fix
// before Service svc = new MyService(); svc.init(null); // ServiceStateException // after Service svc = new MyService(); svc.init(Objects.requireNonNull(conf, "conf must be resolved before init"));
Defensive patterns
Strategy: validation
Validate before calling
Objects.requireNonNull(conf, "Configuration must be resolved before service.init()");
if (!service.isInState(Service.STATE.NOTINITED)) {
throw new IllegalStateException("init() only valid from NOTINITED, state=" + service.getServiceState());
} Prevention
- Never call init(null); resolve Configuration first (propagate the parent's conf in composites).
- Null-check conf at construction time so failures carry the creator's stack trace.
- In tests, share one new Configuration() fixture instead of passing null.
When it happens
Trigger: Programmatically deploying a service and calling service.init(null): hand-written wiring, test fixtures, or refactors that drop the conf parameter; CompositeService children initialized with a null propagated config.
Common situations: Unit tests initializing services with null; wrapper/factory code that builds Configuration lazily and passes null by mistake; code migrated from APIs where conf was optional.
Related errors
- Cannot close proxy since it is null
- ${name}: for this operation, the current service state must
- ${name} cannot enter state ${proposed} from state ${state}
- Producer in KafkaSink is null!
- No more entry in " + f
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/54adbae09003101f.
Report an issue: GitHub.