{"record":{"id":"e93bf9811be87e35","repo":"apache/hadoop","slug":"invalid-outputs-length","errorCode":null,"errorMessage":"Invalid outputs length","messagePattern":"Invalid outputs length","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/coder/HHXORErasureDecodingStep.java","lineNumber":94,"sourceCode":"    performCoding(inputBuffers, outputBuffers);\n  }\n\n  private void performCoding(ByteBuffer[] inputs, ByteBuffer[] outputs)\n      throws IOException {\n    final int numDataUnits = rsRawDecoder.getNumDataUnits();\n    final int numParityUnits = rsRawDecoder.getNumParityUnits();\n    final int numTotalUnits = numDataUnits + numParityUnits;\n    final int subPacketSize = getSubPacketSize();\n\n    ByteBuffer fisrtValidInput = HHUtil.findFirstValidInput(inputs);\n    final int bufSize = fisrtValidInput.remaining();\n\n    if (inputs.length != numTotalUnits * getSubPacketSize()) {\n      throw new IllegalArgumentException(\"Invalid inputs length\");\n    }\n\n    if (outputs.length != erasedIndexes.length * getSubPacketSize()) {\n      throw new IllegalArgumentException(\"Invalid outputs length\");\n    }\n\n    // notes:inputs length = numDataUnits * subPacketizationSize\n    // first numDataUnits length is first sub-stripe,\n    // second numDataUnits length is second sub-stripe\n    ByteBuffer[][] newIn = new ByteBuffer[subPacketSize][numTotalUnits];\n    for (int i = 0; i < subPacketSize; ++i) {\n      for (int j = 0; j < numTotalUnits; ++j) {\n        newIn[i][j] = inputs[i * numTotalUnits + j];\n      }\n    }\n\n    ByteBuffer[][] newOut = new ByteBuffer[subPacketSize][erasedIndexes.length];\n    for (int i = 0; i < subPacketSize; ++i) {\n      for (int j = 0; j < erasedIndexes.length; ++j) {\n        newOut[i][j] = outputs[i * erasedIndexes.length + j];\n      }\n    }","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/coder/HHXORErasureDecodingStep.java#L76-L112","documentation":"The HHXOR (Hitchhiker-XOR) decoding step requires outputs.length == erasedIndexes.length * subPacketSize (subPacketSize 2): every erased unit being recovered needs one output buffer per sub-stripe. An RS-style output array with one buffer per erased unit fails this check with IllegalArgumentException.","triggerScenarios":"Calling HHXORErasureDecodingStep.performCoding with outputs sized erasedIndexes.length instead of erasedIndexes.length * 2, or an erasedIndexes array that disagrees with the number of output blocks passed in.","commonSituations":"Reusing RS decode scaffolding under a hhxor policy without doubling output allocation; inconsistent erasedIndexes vs outputBlocks when the step is constructed manually.","solutions":["Size outputs as erasedIndexes.length * 2 buffers (subPacketSize 2)","Keep erasedIndexes consistent with the output blocks handed to the step constructor","Use HHXORErasureCodec's decoder so buffer shape matches the codec's expectations"],"exampleFix":"// before\nByteBuffer[] outputs = new ByteBuffer[erasedIndexes.length]; // one per erased unit\n// throws: Invalid outputs length\n\n// after\nByteBuffer[] outputs = new ByteBuffer[erasedIndexes.length * 2]; // subPacketSize 2","handlingStrategy":"validation","validationCode":"int sub = 2;\nif (outputBuffers.length != erasedIndexes.length * sub) {\n  throw new IllegalStateException(\"Allocate \" + erasedIndexes.length * sub\n      + \" output buffers (\" + erasedIndexes.length + \" erased units x \" + sub + \")\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  step.performCoding(in, out);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"outputs length\")) reallocateOutputsAndRetry();\n}","preventionTips":["Allocate outputs and record erasedIndexes in the same code block so they cannot diverge","Encapsulate hhxor buffer-shape rules in one helper used by all call sites","Add unit tests asserting buffer shapes for the hhxor codec"],"tags":["erasure-coding","hitchhiker","hhxor","buffer-mismatch"],"backgroundTag":"buffer-length-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}