{"record":{"id":"b3a670d462977198","repo":"apache/hadoop","slug":"algorithm-not-matched-expected-algorithm-rece","errorCode":null,"errorMessage":"Algorithm not matched. Expected ${algorithm}, Received ${checksum.getAlgorithmName()}","messagePattern":"Algorithm not matched\\. Expected (.+?), Received (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java","lineNumber":568,"sourceCode":"        MD5MD5CRC32FileChecksum.getCrcTypeFromAlgorithmName(algorithm);\n    final MD5MD5CRC32FileChecksum checksum;\n\n    // Recreate what DFSClient would have returned.\n    switch(crcType) {\n    case CRC32:\n      checksum = new MD5MD5CRC32GzipFileChecksum();\n      break;\n    case CRC32C:\n      checksum = new MD5MD5CRC32CastagnoliFileChecksum();\n      break;\n    default:\n      throw new IOException(\"Unknown algorithm: \" + algorithm);\n    }\n    checksum.readFields(in);\n\n    //check algorithm name\n    if (!checksum.getAlgorithmName().equals(algorithm)) {\n      throw new IOException(\"Algorithm not matched. Expected \" + algorithm\n          + \", Received \" + checksum.getAlgorithmName());\n    }\n    //check length\n    if (length != checksum.getLength()) {\n      throw new IOException(\"Length not matched: length=\" + length\n          + \", checksum.getLength()=\" + checksum.getLength());\n    }\n\n    return checksum;\n  }\n\n  /** Convert a Json map to a AclStatus object. */\n  static AclStatus toAclStatus(final Map<?, ?> json) {\n    if (json == null) {\n      return null;\n    }\n\n    final Map<?, ?> m = (Map<?, ?>) json.get(AclStatus.class.getSimpleName());","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java#L550-L586","documentation":"After selecting a CRC32 or CRC32C checksum class, JsonUtilClient reads the bytes field into that object and then compares the reconstructed algorithm name with the algorithm string sent by the server. The composite name includes crcPerBlock, bytesPerCRC, and CRC type, so this IOException means the encoded checksum bytes and advertised algorithm describe different parameters.","triggerScenarios":"getFileChecksum through WebHDFS returns a FileChecksum JSON object whose algorithm string does not equal the algorithm reconstructed from its bytes. This is a consistency failure in the response, typically caused by a proxy or mock changing one field independently of the other, or by an incompatible server/client serialization.","commonSituations":"A gateway caches or rewrites the algorithm field; a hand-built JSON response combines values from different files or Hadoop versions; response corruption through an HTTP intermediary; version drift between WebHDFS client and NameNode.","solutions":["Call the NameNode WebHDFS endpoint directly with curl or a matching Hadoop client and inspect the complete FileChecksum JSON.","Disable or fix checksum-response rewriting in reverse proxies, caches, and test gateways.","Use matching Hadoop client and cluster versions.","Treat the response as invalid rather than retrying the same request, and compute a digest by reading the file if an application checksum is required."],"exampleFix":"// before: server sends algorithm=MD5-of-0MD5-of-512CRC32\n// but bytes encode MD5-of-0MD5-of-512CRC32C\nFileChecksum cs = fs.getFileChecksum(path);\n\n// after: use the cluster NameNode directly so algorithm and bytes match\nFileSystem fs = FileSystem.get(new URI(\"webhdfs://namenode:9870\"), conf);\nFileChecksum cs = fs.getFileChecksum(path);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return fs.getFileChecksum(path);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Algorithm not matched\")) {\n    throw new IOException(\"Server checksum response is inconsistent; verify gateway/server compatibility for \" + path, e);\n  }\n  throw e;\n}","preventionTips":["Never modify the algorithm field independently of the bytes field in WebHDFS fixtures or gateways.","Compare checksums only between clients and servers from compatible Hadoop versions.","Log the raw FileChecksum JSON when consistency failures occur so the mismatched field is visible."],"tags":["java","hadoop","webhdfs","checksum","response-validation"],"backgroundTag":"checksum-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}