apache/hadoop · error · FileNotFoundException
Mailformed URL while finding the web resource dir:{}
Error message
Mailformed URL while finding the web resource dir:{} What it means
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.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java:1353
}
/**
* Get the pathname to the webapps files.
* @param appName eg "secondary" or "datanode"
* @return the pathname as a URL
* @throws FileNotFoundException if 'webapps' directory cannot be found
* on CLASSPATH or in the development location.
*/
protected String getWebAppsPath(String appName) throws FileNotFoundException {
URL resourceUrl = null;
File webResourceDevLocation = new File("src/main/webapps", appName);
if (webResourceDevLocation.exists()) {
LOG.info("Web server is in development mode. Resources "
+ "will be read from the source tree.");
try {
resourceUrl = webResourceDevLocation.getParentFile().toURI().toURL();
} catch (MalformedURLException e) {
throw new FileNotFoundException("Mailformed URL while finding the "
+ "web resource dir:" + e.getMessage());
}
} else {
resourceUrl =
getClass().getClassLoader().getResource("webapps/" + appName);
if (resourceUrl == null) {
throw new FileNotFoundException("webapps/" + appName +
" not found in CLASSPATH");
}
}
String urlString = resourceUrl.toString();
return urlString.substring(0, urlString.lastIndexOf('/'));
}
/**
* Get the port that the server is on
* @return the portView on GitHub (pinned to 2add963021)
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
Defensive patterns
Strategy: try-catch
Validate before calling
File dev = new File("src/main/webapps", appName);
if (dev.exists()) {
try { dev.getParentFile().toURI().toURL(); }
catch (MalformedURLException e) { /* run from a normal directory or package instead */ }
} Try / catch
try {
path = server.getWebAppsPath(appName);
} catch (FileNotFoundException e) {
// fall back to explicit classpath-based resource or an absolute webapps dir
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Development checkouts where the process working directory is odd (symlink farms, containers with strange mounts); extremely rare in packaged clusters.
Related errors
- Property %s not specified
- unknown scheme for endpoint:{}
- webapps/{} not found in CLASSPATH
- Problem in starting http server. Server handlers failed
- Unable to initialize WebAppContext
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/c669d4030ea7104a.
Report an issue: GitHub.