{"record":{"id":"8a460fe5c55e25d9","repo":"apache/hadoop","slug":"unable-to-initialize-webappcontext","errorCode":null,"errorMessage":"Unable to initialize WebAppContext","messagePattern":"Unable to initialize WebAppContext","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java","lineNumber":1485,"sourceCode":"      } catch (MultiException ex) {\n        LOG.info(\"HttpServer.start() threw a MultiException\", ex);\n        throw ex;\n      }\n      // Make sure there is no handler failures.\n      Handler[] hs = webServer.getHandlers();\n      for (Handler handler : hs) {\n        if (handler.isFailed()) {\n          throw new IOException(\n              \"Problem in starting http server. Server handlers failed\");\n        }\n      }\n      // Make sure there are no errors initializing the context.\n      Throwable unavailableException = webAppContext.getUnavailableException();\n      if (unavailableException != null) {\n        // Have to stop the webserver, or else its non-daemon threads\n        // will hang forever.\n        webServer.stop();\n        throw new IOException(\"Unable to initialize WebAppContext\",\n            unavailableException);\n      }\n    } catch (IOException e) {\n      throw e;\n    } catch (InterruptedException e) {\n      throw (IOException) new InterruptedIOException(\n          \"Interrupted while starting HTTP server\").initCause(e);\n    } catch (Exception e) {\n      throw new IOException(\"Problem starting http server\", e);\n    }\n  }\n\n  private void loadListeners() {\n    for (Connector c : listeners) {\n      webServer.addConnector(c);\n    }\n  }\n","sourceCodeStart":1467,"sourceCodeEnd":1503,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java#L1467-L1503","documentation":"If the webapp's WebAppContext initialized but ended up unavailable (Jetty's getUnavailableException() non-null), HttpServer2 stops the whole server first (to kill Jetty's non-daemon threads) and then throws IOException 'Unable to initialize WebAppContext' with the unavailable throwable as the cause. Typical causes are web.xml errors, missing servlet/listener classes, or JSP/tag compile failures in the webapp.","triggerScenarios":"web.xml referencing a class not on the classpath; a ServletContextListener (e.g., Hadoop's own or a custom one) throwing during contextInitialized; missing webapps static resources after packaging changes; JSP compilation problems on exotic JDK versions.","commonSituations":"Custom webapps added to a daemon; upgrading Jetty/JDK where a listener becomes incompatible; packaging changes (see also 'webapps not found in CLASSPATH') that half-deploy a webapp.","solutions":["Read the cause attached to this IOException - it is the actual context init failure with its stack trace","Verify every class named in the webapp's web.xml and every context listener is on the daemon classpath","Confirm webapps/<app> resources are complete and the web.xml parses","If a custom webapp is at fault, remove/disable it to bring the daemon up, then fix it separately"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  httpServer.start();\n} catch (IOException e) {\n  if (\"Unable to initialize WebAppContext\".equals(e.getMessage())) {\n    Throwable root = e.getCause(); // the context's unavailableException - real cause\n    // fix web.xml / listener / classpath issues named there\n  }\n}","preventionTips":["Validate web.xml classes and listeners at build time","Keep custom webapps simple and covered by startup smoke tests","After packaging changes, diff the webapps resources shipped before and after"],"tags":["hadoop","http-server","jetty","servlet","webxml","startup"],"backgroundTag":"servlet-context-unavailable","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}