{"record":{"id":"6d0d42745a46ec85","repo":"apache/flink","slug":"configuration-cannot-evaluate-value-s-as-a-byte","errorCode":null,"errorMessage":"Configuration cannot evaluate value %s as a byte[] value","messagePattern":"Configuration cannot evaluate value (.+?) as a byte\\[\\] value","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/configuration/Configuration.java","lineNumber":156,"sourceCode":"    }\n\n    /**\n     * Returns the value associated with the given key as a byte array.\n     *\n     * @param key The key pointing to the associated value.\n     * @param defaultValue The default value which is returned in case there is no value associated\n     *     with the given key.\n     * @return the (default) value associated with the given key.\n     */\n    @Internal\n    public byte[] getBytes(String key, byte[] defaultValue) {\n        return getRawValue(key)\n                .map(\n                        o -> {\n                            if (o.getClass().equals(byte[].class)) {\n                                return (byte[]) o;\n                            } else {\n                                throw new IllegalArgumentException(\n                                        String.format(\n                                                \"Configuration cannot evaluate value %s as a byte[] value\",\n                                                o));\n                            }\n                        })\n                .orElse(defaultValue);\n    }\n\n    /**\n     * Adds the given byte array to the configuration object. If key is <code>null</code> then\n     * nothing is added.\n     *\n     * @param key The key under which the bytes are added.\n     * @param bytes The bytes to be added.\n     */\n    @Internal\n    public void setBytes(String key, byte[] bytes) {\n        setValueInternal(key, bytes);","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/configuration/Configuration.java#L138-L174","documentation":"Configuration.getBytes(key, default) is the legacy typed getter: it looks up the raw stored value and, unless the stored object's class is exactly byte[], throws IllegalArgumentException 'Configuration cannot evaluate value %s as a byte[] value'. Unlike modern ConfigOption getters it does no string coercion — the value must have been put as a byte array via setBytes/setValue(byte[]) or parsed as TYPE_BYTES.","triggerScenarios":"Calling getBytes on a key whose value was stored as String, Integer, Boolean, or any non-byte[] type (e.g. read from flink-conf.yaml where everything parses to a String); mixing the old String-keyed API with YAML-loaded values.","commonSituations":"Legacy code paths calling conf.getBytes(\"some.key\", null) on keys defined in the YAML config file; internal utilities expecting byte[] set programmatically but the key was overridden in configuration files.","solutions":["Store the value as byte[] (conf.setBytes(key, bytes)) instead of a string, if you must use getBytes.","Migrate to the ConfigOption API: define ConfigOption<byte[]> or parse explicitly: BaseEncoding.base64().decode(conf.getString(key)).","If the value may legitimately be a string encoding of bytes, read it with getString and decode it yourself."],"exampleFix":"// before\nbyte[] secret = conf.getBytes(\"security.secret\", null); // key came from YAML as String -> throws\n\n// after\nbyte[] secret = java.util.Base64.getDecoder().decode(conf.getString(\"security.secret\", \"\"));","handlingStrategy":"type-guard","validationCode":"Object raw = conf.getRawValue(key).orElse(null);\nif (raw != null && !raw.getClass().equals(byte[].class)) {\n    throw new IllegalArgumentException(\"Key '\" + key + \"' is \" + raw.getClass().getSimpleName() + \", not byte[]\");\n}","typeGuard":"boolean isByteValue(Configuration conf, String key) {\n    return conf.getRawValue(key).map(o -> o.getClass().equals(byte[].class)).orElse(true);\n}","tryCatchPattern":null,"preventionTips":["Do not use the legacy getBytes on YAML-loaded configuration — values there are Strings.","Standardize on the ConfigOption API for new code.","Encode binary data as base64 strings if it must round-trip through config files."],"tags":["configuration","type-mismatch","legacy-api","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}