{"record":{"id":"c08058a686cefe5c","repo":"apache/hadoop","slug":"content-type-contenttype-is-incompatible-with","errorCode":null,"errorMessage":"Content-Type \"${contentType}\" is incompatible with \"application/json\" (parsed=\"${parsed}\")","messagePattern":"Content-Type \"(.+?)\" is incompatible with \"application/json\" \\(parsed=\"(.+?)\"\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java","lineNumber":499,"sourceCode":"\n  @VisibleForTesting\n  public static Map<?, ?> jsonParse(final HttpURLConnection c,\n      final boolean useErrorStream) throws IOException {\n    if (c.getContentLength() == 0) {\n      return null;\n    }\n    final InputStream in = useErrorStream ?\n        c.getErrorStream() : c.getInputStream();\n    if (in == null) {\n      throw new IOException(\"The \" + (useErrorStream? \"error\": \"input\") +\n          \" stream is null.\");\n    }\n    try {\n      final String contentType = c.getContentType();\n      if (contentType != null) {\n        final MediaType parsed = MediaType.valueOf(contentType);\n        if (!MediaType.APPLICATION_JSON_TYPE.isCompatible(parsed)) {\n          throw new IOException(\"Content-Type \\\"\" + contentType\n              + \"\\\" is incompatible with \\\"\" + MediaType.APPLICATION_JSON\n              + \"\\\" (parsed=\\\"\" + parsed + \"\\\")\");\n        }\n      }\n      return JsonSerialization.mapReader().readValue(in);\n    } finally {\n      in.close();\n    }\n  }\n\n  private static Map<?, ?> validateResponse(final HttpOpParam.Op op,\n      final HttpURLConnection conn, boolean unwrapException)\n      throws IOException {\n    final int code = conn.getResponseCode();\n    // server is demanding an authentication we don't support\n    if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {\n      // match hdfs/rpc exception\n      throw new AccessControlException(conn.getResponseMessage());","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java#L481-L517","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the full endpoint URL, normally http(s)://namenode-or-httpfs:port/webhdfs/v1/..., and use the correct WebHDFS port.","Run curl -i on the failing URL and inspect the returned Content-Type and body to identify which service answered.","Fix reverse-proxy routing and error-page configuration so WebHDFS responses, including errors, are passed through unchanged.","Confirm authentication configuration, because an HTML authentication challenge or portal page can also produce this error."],"exampleFix":"# before\nFileSystem fs = FileSystem.get(new URI(\"webhdfs://nn:50470\"), conf);\n\n# after: use the WebHDFS HTTP endpoint\nFileSystem fs = FileSystem.get(new URI(\"webhdfs://nn:9870\"), conf);\n\n# verify with\ncurl -i \"http://nn:9870/webhdfs/v1/?op=LISTSTATUS\"","handlingStrategy":"try-catch","validationCode":"URI uri = fs.getUri();\nif (!(\"webhdfs\".equals(uri.getScheme()) || \"swebhdfs\".equals(uri.getScheme()))) {\n  throw new IllegalArgumentException(\"Not a WebHDFS FileSystem: \" + uri);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return fs.getFileStatus(path);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"is incompatible with \\\"application/json\\\"\")) {\n    throw new IllegalStateException(\"WebHDFS request was answered by a non-JSON endpoint or proxy page; check the URI and port\", e);\n  }\n  throw e;\n}","preventionTips":["Use webhdfs:// or swebhdfs:// URIs with the correct NameNode/HttpFS port.","Test endpoint routing with curl -i before deploying clients behind proxies.","Do not point WebHDFS clients at management, S3, or application REST endpoints."],"tags":["java","hadoop","webhdfs","http","content-type","json"],"backgroundTag":"unexpected-content-type","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}