{"record":{"id":"54adbae09003101f","repo":"apache/hadoop","slug":"cannot-initialize-service-name-null-configurat","errorCode":null,"errorMessage":"Cannot initialize service ${name}: null configuration","messagePattern":"Cannot initialize service (.+?): null configuration","errorType":"exception","errorClass":"ServiceStateException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/service/AbstractService.java","lineNumber":155,"sourceCode":"   * needs to override that initial setting -for example replacing\n   * it with a new subclass of {@link Configuration}\n   * @param conf new configuration.\n   */\n  protected void setConfig(Configuration conf) {\n    this.config = conf;\n  }\n\n  /**\n   * {@inheritDoc}\n   * This invokes {@link #serviceInit}\n   * @param conf the configuration of the service. This must not be null\n   * @throws ServiceStateException if the configuration was null,\n   * the state change not permitted, or something else went wrong\n   */\n  @Override\n  public void init(Configuration conf) {\n    if (conf == null) {\n      throw new ServiceStateException(\"Cannot initialize service \"\n                                      + getName() + \": null configuration\");\n    }\n    if (isInState(STATE.INITED)) {\n      return;\n    }\n    synchronized (stateChangeLock) {\n      if (enterState(STATE.INITED) != STATE.INITED) {\n        setConfig(conf);\n        try {\n          serviceInit(config);\n          if (isInState(STATE.INITED)) {\n            //if the service ended up here during init,\n            //notify the listeners\n            notifyListeners();\n          }\n        } catch (Exception e) {\n          noteFailure(e);\n          ServiceOperations.stopQuietly(LOG, this);","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/service/AbstractService.java#L137-L173","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nService svc = new MyService();\nsvc.init(null); // ServiceStateException\n// after\nService svc = new MyService();\nsvc.init(Objects.requireNonNull(conf, \"conf must be resolved before init\"));","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(conf, \"Configuration must be resolved before service.init()\");\nif (!service.isInState(Service.STATE.NOTINITED)) {\n  throw new IllegalStateException(\"init() only valid from NOTINITED, state=\" + service.getServiceState());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["service","lifecycle","configuration","null-check"],"backgroundTag":"null-configuration","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}