{"record":{"id":"189741baf08220b0","repo":"zhisheng17/flink-learning","slug":"bytes-null","errorCode":null,"errorMessage":"bytes == null","messagePattern":"bytes == null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-learning-core/src/main/java/com/zhisheng/core/utils/StringUtils.java","lineNumber":59,"sourceCode":"public final class StringUtils {\n\n\tprivate static final char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };\n\n\t/**\n\t * Given an array of bytes it will convert the bytes to a hex string\n\t * representation of the bytes.\n\t *\n\t * @param bytes\n\t *        the bytes to convert in a hex string\n\t * @param start\n\t *        start index, inclusively\n\t * @param end\n\t *        end index, exclusively\n\t * @return hex string representation of the byte array\n\t */\n\tpublic static String byteToHexString(final byte[] bytes, final int start, final int end) {\n\t\tif (bytes == null) {\n\t\t\tthrow new IllegalArgumentException(\"bytes == null\");\n\t\t}\n\n\t\tint length = end - start;\n\t\tchar[] out = new char[length * 2];\n\n\t\tfor (int i = start, j = 0; i < end; i++) {\n\t\t\tout[j++] = HEX_CHARS[(0xF0 & bytes[i]) >>> 4];\n\t\t\tout[j++] = HEX_CHARS[0x0F & bytes[i]];\n\t\t}\n\n\t\treturn new String(out);\n\t}\n\n\t/**\n\t * Given an array of bytes it will convert the bytes to a hex string\n\t * representation of the bytes.\n\t *\n\t * @param bytes","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-core/src/main/java/com/zhisheng/core/utils/StringUtils.java#L41-L77","documentation":"StringUtils.byteToHexString converts a byte array (or a range of it) to a hex string. It explicitly rejects a null array with IllegalArgumentException('bytes == null') rather than returning null, since a null has no hex representation.","triggerScenarios":"Calling byteToHexString(null, start, end) or byteToHexString(null) where the byte array reference is null — typically the result of a method that returned null (e.g. digest/decode call) passed straight through.","commonSituations":"Hashing utilities receiving null input from optional fields, deserialized records with missing byte payloads, or APIs returning null instead of empty arrays.","solutions":["Null-check the byte array before calling byteToHexString","Ensure the producer of the bytes returns an empty array instead of null","Return an empty string for null at your call site if that is the desired semantics"],"exampleFix":"// before\nString hex = StringUtils.byteToHexString(bytes, 0, bytes.length);\n// after\nString hex = bytes == null ? \"\" : StringUtils.byteToHexString(bytes, 0, bytes.length);","handlingStrategy":"type-guard","validationCode":"if (bytes == null) {\n    throw new IllegalArgumentException(\"byte array must not be null before hex encoding\");\n}","typeGuard":"static boolean isNonNullBytes(byte[] b) {\n    return b != null;\n}","tryCatchPattern":"try {\n    String hex = StringUtils.byteToHexString(bytes, 0, bytes.length);\n} catch (IllegalArgumentException e) {\n    if (\"bytes == null\".equals(e.getMessage())) {\n        hex = \"\"; // or handle absent payload explicitly\n    } else throw e;\n}","preventionTips":["Treat byte[] results from hashing/decoding APIs as Optional and unwrap with a default","Never pass possibly-null byte arrays straight into utility methods","Prefer returning byte[0] over null from your own byte-producing methods"],"tags":["java","null","hex","utils"],"backgroundTag":"null-argument","analyzedSha":"d731cee7618021be56d132cc925102ffff8d75e6","analyzedAt":"2026-09-06T05:35:08.496Z","contentChangedAt":"2026-09-06T05:35:08.496Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}