apache/hadoop · error · InvalidUriException

URL is malformed

Error message

URL is malformed{url}

What it means

The assembled request URL string (baseUrl + encoded path + query) could not be parsed by java.net.URL — MalformedURLException wrapped into InvalidUriException. Some component of the URL (protocol, host, or an unencodable character that survived) is not legal for java.net.URL.

Solutions

  1. Print the malformed URL from the exception message and inspect protocol/host for typos or stray whitespace.
  2. Correct the endpoint configuration (scheme https/abfs(s), full storage host).
  3. Check templating/env-var substitution that builds the URL for inserted characters.

Example fix

# before (typo: single slash after scheme)
fs.azure.account.oauth.provider.msft.endpoint=https:/login.microsoftonline.com/...
# after
fs.azure.account.oauth.provider.msft.endpoint=https://login.microsoftonline.com/...
# preflight any configurable URL
try { new URL(candidate); } catch (MalformedURLException e) { failFast(candidate); }
Defensive patterns

Strategy: validation

Validate before calling

try {
  new URL(candidateEndpoint);
} catch (MalformedURLException e) {
  throw new IllegalArgumentException("Bad endpoint URL: " + candidateEndpoint, e);
}

Try / catch

catch (InvalidUriException ex) {
  if (ex.getMessage().startsWith("URL is malformed")) {
    // the message embeds the full URL: inspect scheme/host for typos or injected chars
  } else throw ex;
}

Prevention

When it happens

Trigger: An endpoint URL with a typo in the scheme (e.g. 'abfss:/' or 'https:/'), a host containing illegal characters, or a path segment producing characters that remain invalid after encoding, so new URL(...) throws.

Common situations: Hand-edited endpoint configuration with missing slashes; environment variables or templating inserting spaces/newlines into URLs; proxy rewrite rules mangling endpoint URLs; containers built from different distributions whose defaults differ.

Understand the failure class

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/7846acb7f5bb45d8. Report an issue: GitHub.

Appendix: source

Thrown at hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java:1244

      encodedPath = urlEncode(path);
    } catch (AzureBlobFileSystemException ex) {
      LOG.debug("Unexpected error.", ex);
      throw new InvalidUriException(path);
    }

    final StringBuilder sb = new StringBuilder();
    if (baseUrl == null) {
      throw new InvalidUriException("URL provided is null");
    }
    sb.append(baseUrl.toString());
    sb.append(encodedPath);
    sb.append(query);

    final URL url;
    try {
      url = new URL(sb.toString());
    } catch (MalformedURLException ex) {
      throw new InvalidUriException("URL is malformed" + sb.toString());
    }
    return url;
  }

  /**
   * returns the url encoded string for a given value.
   * @param value to be encoded.
   * @return url encoded string.
   * @throws AzureBlobFileSystemException if encoding fails.
   */
  public static String urlEncode(final String value) throws AzureBlobFileSystemException {
    String encodedString;
    try {
      encodedString =  URLEncoder.encode(value, UTF_8)
          .replace(PLUS, PLUS_ENCODE)
          .replace(FORWARD_SLASH_ENCODE, FORWARD_SLASH);
    } catch (UnsupportedEncodingException ex) {
        throw new InvalidUriException(value);

View on GitHub (pinned to 2add963021)