{"record":{"id":"9db1d042a39d1479","repo":"apache/hadoop","slug":"invalid-buffer-found-not-allowing-null-9db1d0","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/ByteArrayEncodingState.java","lineNumber":94,"sourceCode":"    }\n\n    for (int i = 0; i < outputs.length; i++) {\n      newOutputs[i] = ByteBuffer.allocateDirect(encodeLength);\n    }\n\n    ByteBufferEncodingState bbeState = new ByteBufferEncodingState(encoder,\n        encodeLength, newInputs, newOutputs);\n    return bbeState;\n  }\n\n  /**\n   * Check and ensure the buffers are of the desired length.\n   * @param buffers the buffers to check\n   */\n  void checkBuffers(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 != encodeLength) {\n        throw new HadoopIllegalArgumentException(\n            \"Invalid buffer not of length \" + encodeLength);\n      }\n    }\n  }\n}\n","sourceCodeStart":76,"sourceCodeEnd":105,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/rawcoder/ByteArrayEncodingState.java#L76-L105","documentation":"For byte-array encoding, ByteArrayEncodingState.checkBuffers is applied to both the input and output arrays and rejects any null element with HadoopIllegalArgumentException(\"Invalid buffer found, not allowing null\"). Encoding has no erased-unit concept: every data input and every parity output must be a real allocated array.","triggerScenarios":"Calling RawErasureEncoder.encode(byte[][], byte[][]) with a null element in either array — e.g., an input slot left null because its read failed, or outputs allocated as an array of nulls.","commonSituations":"Reusing decode-style null placeholders in encode calls; buffer pools returning null under pressure; partially filled arrays passed before all chunks were fetched.","solutions":["Ensure every input and output byte[] is allocated before encode; there is no legal null in the encode path","If a data chunk is unavailable, fail the encode explicitly rather than passing null","Add a null scan over both arrays right before calling encode"],"exampleFix":"// before\nbyte[][] inputs = new byte[numDataUnits][]; // some slots still null\nencoder.encode(inputs, outputs); // throws\n\n// after\nfor (int i = 0; i < inputs.length; i++) {\n  if (inputs[i] == null) throw new IllegalStateException(\"missing input \" + i);\n}\nencoder.encode(inputs, outputs);","handlingStrategy":"validation","validationCode":"for (byte[] b : inputs) {\n  if (b == null) throw new IllegalStateException(\"encode input null\");\n}\nfor (byte[] b : outputs) {\n  if (b == null) throw new IllegalStateException(\"encode output null\");\n}\nencoder.encode(inputs, outputs);","typeGuard":null,"tryCatchPattern":"try {\n  encoder.encode(inputs, outputs);\n} catch (HadoopIllegalArgumentException e) {\n  if (e.getMessage().contains(\"not allowing null\")) {\n    // fill the null slot with a real buffer (encode allows no nulls) and retry\n  }\n}","preventionTips":["Remember the asymmetry: decode inputs may be null (erased), encode arrays may not","Fail loudly when a chunk to encode is missing instead of passing null","Scan both arrays for nulls in a shared pre-encode guard"],"tags":["erasure-coding","buffer-validation","null-check"],"backgroundTag":"null-buffer-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}