{"record":{"id":"c669d4030ea7104a","repo":"apache/hadoop","slug":"mailformed-url-while-finding-the-web-resource-dir","errorCode":null,"errorMessage":"Mailformed URL while finding the web resource dir:{}","messagePattern":"Mailformed URL while finding the web resource dir:(.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java","lineNumber":1353,"sourceCode":"  }\n\n  /**\n   * Get the pathname to the webapps files.\n   * @param appName eg \"secondary\" or \"datanode\"\n   * @return the pathname as a URL\n   * @throws FileNotFoundException if 'webapps' directory cannot be found\n   *   on CLASSPATH or in the development location.\n   */\n  protected String getWebAppsPath(String appName) throws FileNotFoundException {\n    URL resourceUrl = null;\n    File webResourceDevLocation = new File(\"src/main/webapps\", appName);\n    if (webResourceDevLocation.exists()) {\n      LOG.info(\"Web server is in development mode. Resources \"\n          + \"will be read from the source tree.\");\n      try {\n        resourceUrl = webResourceDevLocation.getParentFile().toURI().toURL();\n      } catch (MalformedURLException e) {\n        throw new FileNotFoundException(\"Mailformed URL while finding the \"\n            + \"web resource dir:\" + e.getMessage());\n      }\n    } else {\n      resourceUrl =\n          getClass().getClassLoader().getResource(\"webapps/\" + appName);\n\n      if (resourceUrl == null) {\n        throw new FileNotFoundException(\"webapps/\" + appName +\n            \" not found in CLASSPATH\");\n      }\n    }\n    String urlString = resourceUrl.toString();\n    return urlString.substring(0, urlString.lastIndexOf('/'));\n  }\n\n  /**\n   * Get the port that the server is on\n   * @return the port","sourceCodeStart":1335,"sourceCodeEnd":1371,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java#L1335-L1371","documentation":"HttpServer2.getWebAppsPath() takes a development shortcut when src/main/webapps/<appName> exists on the working directory, converting its parent directory to a URL. If that File.toURI().toURL() throws MalformedURLException, it is rethrown as FileNotFoundException 'Mailformed URL...' (the typo is in the source). In practice this branch almost never fires because File URIs are well-formed; seeing it means the dev-mode path detection matched from an unusual location.","triggerScenarios":"Running a daemon or test from a directory that happens to contain src/main/webapps/<appName> while the path involves unusual characters or a broken filesystem view, making URL conversion fail.","commonSituations":"Development checkouts where the process working directory is odd (symlink farms, containers with strange mounts); extremely rare in packaged clusters.","solutions":["Change the working directory or move/rename the src/main/webapps dir so the classpath-based lookup is used instead","Run against a properly packaged jar where webapps/<app> is a classpath resource"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"File dev = new File(\"src/main/webapps\", appName);\nif (dev.exists()) {\n  try { dev.getParentFile().toURI().toURL(); }\n  catch (MalformedURLException e) { /* run from a normal directory or package instead */ }\n}","typeGuard":null,"tryCatchPattern":"try {\n  path = server.getWebAppsPath(appName);\n} catch (FileNotFoundException e) {\n  // fall back to explicit classpath-based resource or an absolute webapps dir\n}","preventionTips":["Run daemons from a packaged distribution, not from inside a source tree with odd paths","Keep working directories free of accidental src/main/webapps leftovers"],"tags":["hadoop","http-server","url","dev-environment"],"backgroundTag":"malformed-url","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}