{"id":"a9a5e3bf2384d7a9","repo":"apache/kafka","slug":"expected-value-to-be-either-true-or-false","errorCode":null,"errorMessage":"Expected value to be either true or false","messagePattern":"Expected value to be either true or false","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java","lineNumber":719,"sourceCode":"     * @return The parsed object\n     */\n    public static Object parseType(String name, Object value, Type type) {\n        try {\n            if (value == null) return null;\n\n            String trimmed = null;\n            if (value instanceof String)\n                trimmed = ((String) value).trim();\n\n            switch (type) {\n                case BOOLEAN:\n                    if (value instanceof String) {\n                        if (trimmed.equalsIgnoreCase(\"true\"))\n                            return true;\n                        else if (trimmed.equalsIgnoreCase(\"false\"))\n                            return false;\n                        else\n                            throw new ConfigException(name, value, \"Expected value to be either true or false\");\n                    } else if (value instanceof Boolean)\n                        return value;\n                    else\n                        throw new ConfigException(name, value, \"Expected value to be either true or false\");\n                case PASSWORD:\n                    if (value instanceof Password)\n                        return value;\n                    else if (value instanceof String)\n                        return new Password(trimmed);\n                    else\n                        throw new ConfigException(name, value, \"Expected value to be a string, but it was a \" + value.getClass().getName());\n                case STRING:\n                    if (value instanceof String)\n                        return trimmed;\n                    else\n                        throw new ConfigException(name, value, \"Expected value to be a string, but it was a \" + value.getClass().getName());\n                case INT:\n                    if (value instanceof Integer) {","sourceCodeStart":701,"sourceCodeEnd":737,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java#L701-L737","documentation":"Thrown by ConfigDef.parseType in the BOOLEAN branch when the supplied value is a String but, after trimming, is not equal (ignoring case) to \"true\" or \"false\". Boolean configs only accept the two literal strings or a java.lang.Boolean; any other string content fails parsing before any custom Validator runs.","triggerScenarios":"Passing a string such as \"yes\", \"1\", \"on\", \"True \" (extra whitespace is handled, but typos are not), \"enable\", or an empty string to a Type.BOOLEAN config key; reading the value from an env var or YAML/properties file that uses non-canonical truthiness.","commonSituations":"Operator sets enable.auto.commit=yes or auto.offset.reset=true! in a properties file; Helm/Ansible template renders a numeric 1 or the literal 'on' into a boolean field; env var reads 0/1 and is passed unconverted; copy-paste from a tutorial that used a different dialect.","solutions":["Set the property to the literal string true or false (case-insensitive), e.g. enable.auto.commit=false.","If the value originates from an env var or template that emits 0/1, yes/no, or on/off, normalize it to true/false before passing the properties to the Kafka client.","Strip surrounding quotes and whitespace introduced by shell or YAML parsing.","For configs driven by users, document the accepted literals in your property file comments to prevent recurrence."],"exampleFix":"// before\nenable.auto.commit=yes\n\n// after\nenable.auto.commit=false","handlingStrategy":"validation","validationCode":"// A BOOLEAN config value that arrived as a String but isn't 'true'/'false'. Normalize at the boundary.\nstatic String normalizeBooleanString(String name, String raw) {\n    if (raw == null) {\n        throw new IllegalArgumentException(\"Config '\" + name + \"' (boolean) is null.\");\n    }\n    String t = raw.trim();\n    if (t.equalsIgnoreCase(\"true\"))  return \"true\";\n    if (t.equalsIgnoreCase(\"false\")) return \"false\";\n    throw new IllegalArgumentException(\n        \"Config '\" + name + \"' must be \\\"true\\\" or \\\"false\\\" (case-insensitive), got: \" + raw);\n}\n// Apply before putting the value into props:\nprops.setProperty(\"enable.idempotence\", normalizeBooleanString(\"enable.idempotence\", rawValue));","typeGuard":"static boolean isParsableBoolean(Object v) {\n    if (v instanceof Boolean) return true;\n    if (v instanceof String) {\n        String t = ((String) v).trim();\n        return t.equalsIgnoreCase(\"true\") || t.equalsIgnoreCase(\"false\");\n    }\n    return false;\n}","tryCatchPattern":null,"preventionTips":["Pass native java.lang.Boolean values (not strings) whenever constructing props programmatically.","When loading from a properties file/env, normalize every known boolean key through one helper.","Reject values like 'yes','on','1','0' at your config-loading boundary - Kafka only accepts 'true'/'false'.","Document accepted boolean spellings in your deployment guide to prevent ops-side typos."],"tags":["config","boolean","type-coercion","parsing"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}