{"record":{"id":"271f930484a40dee","repo":"greenrobot/greenDAO","slug":"illegal-boolean-value-strings-must-be-true-or","errorCode":null,"errorMessage":"Illegal boolean value: Strings must be \"TRUE\" or \"FALSE\" (case insensitive), but was ","messagePattern":"Illegal boolean value: Strings must be \"TRUE\" or \"FALSE\" \\(case insensitive\\), but was ","errorType":"exception","errorClass":"DaoException","httpStatus":null,"severity":"error","filePath":"DaoCore/src/main/java/org/greenrobot/greendao/query/WhereCondition.java","lineNumber":101,"sourceCode":"                } else {\n                    throw new DaoException(\"Illegal date value: expected java.util.Date or Long for value \" + value);\n                }\n            } else if (property.type == boolean.class || property.type == Boolean.class) {\n                if (value instanceof Boolean) {\n                    return ((Boolean) value) ? 1 : 0;\n                } else if (value instanceof Number) {\n                    int intValue = ((Number) value).intValue();\n                    if (intValue != 0 && intValue != 1) {\n                        throw new DaoException(\"Illegal boolean value: numbers must be 0 or 1, but was \" + value);\n                    }\n                } else if (value instanceof String) {\n                    String stringValue = ((String) value);\n                    if (\"TRUE\".equalsIgnoreCase(stringValue)) {\n                        return 1;\n                    } else if (\"FALSE\".equalsIgnoreCase(stringValue)) {\n                        return 0;\n                    } else {\n                        throw new DaoException(\n                                \"Illegal boolean value: Strings must be \\\"TRUE\\\" or \\\"FALSE\\\" (case insensitive), but was \"\n                                        + value);\n                    }\n                }\n            }\n            return value;\n        }\n\n        private static Object[] checkValuesForType(Property property, Object[] values) {\n            for (int i = 0; i < values.length; i++) {\n                values[i] = checkValueForType(property, values[i]);\n            }\n            return values;\n        }\n\n        public final Property property;\n        public final String op;\n","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoCore/src/main/java/org/greenrobot/greendao/query/WhereCondition.java#L83-L119","documentation":"greenDAO's checkValueForType converts string values used in boolean property conditions to 1/0 for SQL. If the value passed to eq/notEq/etc. for a boolean property is not the string \"TRUE\" or \"FALSE\" (case insensitive), it cannot be mapped and a DaoException is thrown. Passing null, empty string, or \"true\"/\"false\" variants like \"yes\"/\"1\" triggers it.","triggerScenarios":"Calling queryBuilder.where(Property.eq(...)) or similar on a boolean Property with a String value that is not \"TRUE\"/\"FALSE\" (e.g. \"true\", \"\", null, \"1\"); checkValuesForType applies this check to all values of a condition.","commonSituations":"Building dynamic queries where the boolean literal comes from user input, JSON, or a config with lowercase \"true\"/\"false\" conventions; forgetting to pass Boolean.TRUE/FALSE instead of strings; locale/codegen confusion about case handling.","solutions":["Pass a Boolean (true/false) instead of a String for boolean property conditions — checkValueForType maps it correctly.","If a String is required, normalize it to \"TRUE\" or \"FALSE\" before calling where().","Prefer Property.eq(true) helper style so the type system enforces the value.","Wrap condition construction in validation that rejects anything not matching /(?i)^(true|false)$/. My input must be an exact, complete rendering of the following content: "],"exampleFix":"// before\nqueryBuilder.where(Properties.Active.eq(\"true\")); // throws DaoException\n// after\nqueryBuilder.where(Properties.Active.eq(true));\n// or, if a string is unavoidable:\nqueryBuilder.where(Properties.Active.eq(isActive ? \"TRUE\" : \"FALSE\"));","handlingStrategy":"validation","validationCode":"function validBooleanString(v) { return v === true || v === false || /^(true|false)$/i.test(v); }\n// assert validBooleanString(value) before Properties.Active.eq(value); prefer Boolean values","typeGuard":"function isBooleanLiteral(v) { return typeof v === 'boolean' || (typeof v === 'string' && /^(TRUE|FALSE)$/i.test(v)); }","tryCatchPattern":"try {\n    queryBuilder.where(Properties.Active.eq(value)).list();\n} catch (DaoException e) {\n    if (e.getMessage().startsWith(\"Illegal boolean value\")) {\n        throw new IllegalArgumentException(\"Boolean condition value must be true/false or \\\"TRUE\\\"/\\\"FALSE\\\": \" + value, e);\n    }\n    throw e;\n}","preventionTips":["Always pass Boolean true/false to boolean property conditions, never strings","If strings are unavoidable, uppercase-normalize them first","Add a unit test per query condition builder","Never build boolean literals from raw user/JSON input without validation"],"tags":["greendao","query","boolean","type-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"0bbb338e17c4cf28aba5aae62d42f73f50186157","analyzedAt":"2026-09-08T03:22:36.050Z","contentChangedAt":"2026-09-08T03:22:36.050Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}