{"record":{"id":"ff53727254830af9","repo":"apache/hadoop","slug":"zero-length-key-found","errorCode":null,"errorMessage":"zero length key found!","messagePattern":"zero length key found!","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SequenceFile.java","lineNumber":2639,"sourceCode":"        return length;\n      } else {\n        //Reset syncSeen\n        syncSeen = false;\n        \n        // Read 'key'\n        if (noBufferedKeys == 0) {\n          if (in.getPos() >= end) \n            return -1;\n\n          try { \n            readBlock();\n          } catch (EOFException eof) {\n            return -1;\n          }\n        }\n        int keyLength = WritableUtils.readVInt(keyLenIn);\n        if (keyLength < 0) {\n          throw new IOException(\"zero length key found!\");\n        }\n        key.write(keyIn, keyLength);\n        --noBufferedKeys;\n        \n        // Read raw 'value'\n        seekToCurrentValue();\n        int valLength = WritableUtils.readVInt(valLenIn);\n        UncompressedBytes rawValue = (UncompressedBytes)val;\n        rawValue.reset(valIn, valLength);\n        --noBufferedValues;\n        \n        return (keyLength+valLength);\n      }\n      \n    }\n\n    /**\n     * Read 'raw' keys.","sourceCodeStart":2621,"sourceCodeEnd":2657,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SequenceFile.java#L2621-L2657","documentation":"In the block-compressed branch of SequenceFile.Reader.nextRaw(DataOutputBuffer, ValueBytes), the key length is a VInt read from the decompressed key-length block (keyLenIn). A negative value means that block stream is misaligned or damaged, and the guard throws IOException(\"zero length key found!\"). Note the message is slightly misleading: it fires for any keyLength < 0, which always indicates corruption — a well-formed file never writes negative key lengths.","triggerScenarios":"Reading a BLOCK-compressed SequenceFile whose key-length block yields a negative VInt: a corrupt or truncated file, a partially flushed final block from a killed writer, or a decompression codec mismatch (missing/different codec jar) that turns the block into garbage lengths.","commonSituations":"Jobs killed mid-flush leaving partial block tails; LZO/Snappy/Gzip codec jars absent or different versions on the reader classpath; files corrupted in transfer (distcp/checksum mismatches); SequenceFiles read past a truncated HDFS replica.","solutions":["Confirm the file is bad by decoding it independently: `hadoop fs -text <file>` — if that fails too, restore or regenerate the file.","Make sure the exact codec class used at write time is on the reader's classpath and identically configured.","If only the tail is damaged, read up to the last complete block and stop: compare reader.getPosition() with the file length and treat EOF mid-block as end of data.","Re-run the producing job to completion so no partial blocks are written."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  while (reader.nextRaw(keyBuf, valBytes) > 0) { /* ... */ }\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"zero length key\")) {\n    LOG.error(\"Corrupt key block near pos {} in {} — regenerate file\",\n              reader.getPosition(), path);\n    // stop processing this file; mark the input bad and continue with others\n  } else {\n    throw e;\n  }\n}","preventionTips":["Ship the same compression codec jars to writers and readers","Don't kill jobs mid-flush; verify outputs with `hadoop fs -text` after risky transfers","Use checksummed transfers (distcp -crc) when moving SequenceFiles"],"tags":["sequencefile","block-compression","data-corruption","hadoop","io"],"backgroundTag":"data-corruption-detected","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}