{"record":{"id":"410a8350d69cba01","repo":"apache/hadoop","slug":"bytes-null","errorCode":null,"errorMessage":"bytes == null","messagePattern":"bytes == null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java","lineNumber":185,"sourceCode":"    sbuf.append(strs[0]);\n    for (int idx = 1; idx < strs.length; idx++) {\n      sbuf.append(\",\");\n      sbuf.append(strs[idx]);\n    }\n    return sbuf.toString();\n  }\n\n  /**\n   * Given an array of bytes it will convert the bytes to a hex string\n   * representation of the bytes\n   * @param bytes bytes.\n   * @param start start index, inclusively\n   * @param end end index, exclusively\n   * @return hex string representation of the byte array\n   */\n  public static String byteToHexString(byte[] bytes, int start, int end) {\n    if (bytes == null) {\n      throw new IllegalArgumentException(\"bytes == null\");\n    }\n    StringBuilder s = new StringBuilder(); \n    for(int i = start; i < end; i++) {\n      s.append(format(\"%02x\", bytes[i]));\n    }\n    return s.toString();\n  }\n\n  /**\n   * Same as byteToHexString(bytes, 0, bytes.length).\n   * @param bytes bytes.\n   * @return byteToHexString.\n   */\n  public static String byteToHexString(byte bytes[]) {\n    return byteToHexString(bytes, 0, bytes.length);\n  }\n\n  /**","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java#L167-L203","documentation":"StringUtils.byteToHexString(byte[], int, int) renders a byte range as hex and enforces a null precondition: a null array throws IllegalArgumentException('bytes == null') before any iteration. The caller handed it an absent value — typically a digest or buffer that a producer returned as null on failure.","triggerScenarios":"Passing a null byte[] — e.g. messageDigest.digest() result stored without error handling, an uninitialized field, or a map.get(key) miss whose null flows into logging/hex conversion.","commonSituations":"Checksum/hash helpers that return null on exception; optional binary attributes absent from a metadata map; defensive-logging code that itself NPEs on null input.","solutions":["Null-check at the boundary: if (bytes != null) hex = StringUtils.byteToHexString(bytes, 0, bytes.length);","Fix the producer to return an empty array (or throw) instead of null on failure","Use Objects.requireNonNull(bytes, \"bytes\") earlier to fail with your own clearer message","Prefer byteToHexString(bytes, 0, bytes.length) only after length is validated for the start/end range"],"exampleFix":"// before\nString hex = StringUtils.byteToHexString(digest, 0, digest.length); // digest null on hash failure\n\n// after\nbyte[] digest = md != null ? md.digest() : new byte[0];\nString hex = StringUtils.byteToHexString(digest, 0, digest.length);","handlingStrategy":"validation","validationCode":"if (bytes == null) {\n  throw new IllegalArgumentException(\"bytes required for hex conversion\");\n}\nString hex = StringUtils.byteToHexString(bytes, 0, bytes.length);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Design byte-array producers (hashers, serializers) to return empty arrays, not null, on no-data","Null-check at your API boundary before delegating to StringUtils helpers","Use Objects.requireNonNull(bytes, \"bytes\") for fail-fast clarity at the call site"],"tags":["hadoop","stringutils","null-argument","hex-encoding","validation"],"backgroundTag":"null-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}