apache/hadoop · error · IOException

Content-Type "${contentType}" is incompatible with "applicat

Error message

Content-Type "${contentType}" is incompatible with "application/json" (parsed="${parsed}")

What it means

Before parsing WebHDFS JSON, jsonParse verifies that a non-null Content-Type is compatible with application/json. This IOException is thrown when the endpoint answers with another media type, such as text/html, text/plain, or application/octet-stream. The body is deliberately not parsed because it cannot safely be treated as the expected WebHDFS JSON response.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java:499

  @VisibleForTesting
  public static Map<?, ?> jsonParse(final HttpURLConnection c,
      final boolean useErrorStream) throws IOException {
    if (c.getContentLength() == 0) {
      return null;
    }
    final InputStream in = useErrorStream ?
        c.getErrorStream() : c.getInputStream();
    if (in == null) {
      throw new IOException("The " + (useErrorStream? "error": "input") +
          " stream is null.");
    }
    try {
      final String contentType = c.getContentType();
      if (contentType != null) {
        final MediaType parsed = MediaType.valueOf(contentType);
        if (!MediaType.APPLICATION_JSON_TYPE.isCompatible(parsed)) {
          throw new IOException("Content-Type \"" + contentType
              + "\" is incompatible with \"" + MediaType.APPLICATION_JSON
              + "\" (parsed=\"" + parsed + "\")");
        }
      }
      return JsonSerialization.mapReader().readValue(in);
    } finally {
      in.close();
    }
  }

  private static Map<?, ?> validateResponse(final HttpOpParam.Op op,
      final HttpURLConnection conn, boolean unwrapException)
      throws IOException {
    final int code = conn.getResponseCode();
    // server is demanding an authentication we don't support
    if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
      // match hdfs/rpc exception
      throw new AccessControlException(conn.getResponseMessage());

View on GitHub (pinned to 2add963021)

Solutions

  1. Verify the full endpoint URL, normally http(s)://namenode-or-httpfs:port/webhdfs/v1/..., and use the correct WebHDFS port.
  2. Run curl -i on the failing URL and inspect the returned Content-Type and body to identify which service answered.
  3. Fix reverse-proxy routing and error-page configuration so WebHDFS responses, including errors, are passed through unchanged.
  4. Confirm authentication configuration, because an HTML authentication challenge or portal page can also produce this error.

Example fix

# before
FileSystem fs = FileSystem.get(new URI("webhdfs://nn:50470"), conf);

# after: use the WebHDFS HTTP endpoint
FileSystem fs = FileSystem.get(new URI("webhdfs://nn:9870"), conf);

# verify with
curl -i "http://nn:9870/webhdfs/v1/?op=LISTSTATUS"
Defensive patterns

Strategy: try-catch

Validate before calling

URI uri = fs.getUri();
if (!("webhdfs".equals(uri.getScheme()) || "swebhdfs".equals(uri.getScheme()))) {
  throw new IllegalArgumentException("Not a WebHDFS FileSystem: " + uri);
}

Try / catch

try {
  return fs.getFileStatus(path);
} catch (IOException e) {
  if (e.getMessage() != null && e.getMessage().contains("is incompatible with \"application/json\"")) {
    throw new IllegalStateException("WebHDFS request was answered by a non-JSON endpoint or proxy page; check the URI and port", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: A request intended for WebHDFS is answered by a login page, generic proxy error page, management API, or custom service that does not set application/json. jsonParse receives that response and rejects its Content-Type.

Common situations: The URL points to the wrong port or path; a reverse proxy returns an HTML 502/403 page; S3 or another HTTP service is addressed with a webhdfs:// URI; a firewall or servlet renders an error page instead of passing the NameNode response through.

Related errors


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