{"record":{"id":"bb7bea41425a11d4","repo":"apache/hadoop","slug":"invalid-buffer-found-not-allowing-null","errorCode":null,"errorMessage":"Invalid buffer found, not allowing null","messagePattern":"Invalid buffer found, not allowing null","errorType":"exception","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/rawcoder/ByteArrayDecodingState.java","lineNumber":124,"sourceCode":"      }\n\n      validInputs++;\n    }\n\n    if (validInputs < decoder.getNumDataUnits()) {\n      throw new HadoopIllegalArgumentException(\n          \"No enough valid inputs are provided, not recoverable\");\n    }\n  }\n\n  /**\n   * Check and ensure the buffers are of the desired length.\n   * @param buffers the buffers to check\n   */\n  void checkOutputBuffers(byte[][] buffers) {\n    for (byte[] buffer : buffers) {\n      if (buffer == null) {\n        throw new HadoopIllegalArgumentException(\n            \"Invalid buffer found, not allowing null\");\n      }\n\n      if (buffer.length != decodeLength) {\n        throw new HadoopIllegalArgumentException(\n            \"Invalid buffer not of length \" + decodeLength);\n      }\n    }\n  }\n}\n","sourceCodeStart":106,"sourceCodeEnd":135,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/rawcoder/ByteArrayDecodingState.java#L106-L135","documentation":"Unlike inputs (where null marks an erased unit), decode outputs must all be allocated: ByteArrayDecodingState.checkOutputBuffers throws HadoopIllegalArgumentException(\"Invalid buffer found, not allowing null\") on the first null output byte[]. The decoder needs somewhere to write every recovered unit.","triggerScenarios":"Calling decode(byte[][], int[], byte[][]) with any null entry in the outputs array — e.g., reusing an input array containing nulls as the output allocation, or allocating outputs.length fewer buffers than erased units.","commonSituations":"Output arrays sized by a stale erased-unit count; nulls leaking in from buffer pools that hand out null on exhaustion; copy-paste of input allocation patterns (where nulls are legal) to outputs.","solutions":["Allocate a non-null byte[decodeLength] for every output slot before decoding","Size the outputs array to the number of units being recovered and fill every element","Keep null-marking conventions for inputs only; never for outputs"],"exampleFix":"// before\nbyte[][] outputs = new byte[erasedIndexes.length]; // array of nulls\ndecoder.decode(inputs, erased, outputs); // throws\n\n// after\nbyte[][] outputs = new byte[erasedIndexes.length][];\nArrays.fill(outputs, new byte[decodeLength]);","handlingStrategy":"validation","validationCode":"for (byte[] out : outputs) {\n  if (out == null) throw new IllegalStateException(\n      \"Null decode output buffer not allowed; allocate all outputs\");\n}\ndecoder.decode(inputs, erased, outputs);","typeGuard":null,"tryCatchPattern":"try {\n  decoder.decode(inputs, erased, outputs);\n} catch (HadoopIllegalArgumentException e) {\n  if (e.getMessage().contains(\"not allowing null\")) allocateOutputsAndRetry();\n}","preventionTips":["Allocate outputs with Arrays.fill(outputs, new byte[decodeLength]) right after sizing them","Never reuse input arrays (which legally contain nulls) as output containers","Make buffer pools refuse to return null instead of allocating lazily"],"tags":["erasure-coding","buffer-validation","null-check"],"backgroundTag":"null-output-buffer","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}