{"record":{"id":"3bc2f2fb90b1920b","repo":"apache/flink","slug":"bytes-must-not-be-null","errorCode":null,"errorMessage":"Bytes must not be null","messagePattern":"Bytes must not be null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/types/StringValue.java","lineNumber":257,"sourceCode":"\n        ensureSize(len);\n        System.arraycopy(chars, offset, this.value, 0, len);\n        this.len = len;\n        this.hashCode = 0;\n    }\n\n    /**\n     * Sets the value of this <code>StringValue</code>, assuming that the binary data is ASCII\n     * coded. The n-th character of the <code>StringValue</code> corresponds directly to the n-th\n     * byte in the given array after the offset.\n     *\n     * @param bytes The binary character data.\n     * @param offset The offset in the array.\n     * @param len The number of bytes to read from the array.\n     */\n    public void setValueAscii(byte[] bytes, int offset, int len) {\n        if (bytes == null) {\n            throw new NullPointerException(\"Bytes must not be null\");\n        }\n        if (len < 0 || offset < 0 || offset > bytes.length - len) {\n            throw new IndexOutOfBoundsException();\n        }\n\n        ensureSize(len);\n        this.len = len;\n        this.hashCode = 0;\n\n        final char[] chars = this.value;\n\n        for (int i = 0, limit = offset + len; offset < limit; offset++, i++) {\n            chars[i] = (char) (bytes[offset] & 0xff);\n        }\n    }\n\n    // --------------------------------------------------------------------------------------------\n    //                                    String Methods","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/StringValue.java#L239-L275","documentation":"setValueAscii(byte[] bytes, int offset, int len) interprets raw bytes as ASCII chars to set the StringValue's content. It explicitly rejects a null bytes array with NullPointerException ('Bytes must not be null') before any range logic, unlike its sibling setters which rely on checkNotNull elsewhere.","triggerScenarios":"Calling setValueAscii(null, off, len) — e.g. a lookup/decode step returned null for a missing key and the result was passed straight in.","commonSituations":"Map.get() or cache lookups feeding the setter without a null check; optional binary fields deserialized as null; test fixtures omitting the array.","solutions":["Null-check the array before calling: if (bytes == null) use setValue(\"\") or skip the field","Fix the producer so binary fields are never null (use empty arrays)","Annotate/annotate-by-convention the parameter as non-null in your wrapper API"],"exampleFix":"// before\nsv.setValueAscii(map.get(key), 0, n); // NPE when key absent\n\n// after\nbyte[] b = map.get(key);\nif (b == null) {\n    sv.setValue(\"\");\n} else {\n    sv.setValueAscii(b, 0, n);\n}","handlingStrategy":"type-guard","validationCode":"if (bytes == null) {\n    sv.setValue(\"\");\n} else {\n    sv.setValueAscii(bytes, offset, len);\n}","typeGuard":"static boolean isNonEmptyAsciiSource(byte[] b) {\n    return b != null;\n}","tryCatchPattern":null,"preventionTips":["Null-check lookups before passing results","Producers should emit empty arrays, not null","Guard optional binary fields at the deserialization boundary"],"tags":["flink","string-value","null-pointer","ascii"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}