greenrobot/greenDAO · error · DaoException

Illegal boolean value: Strings must be "TRUE" or "FALSE"…

Error message

Illegal boolean value: Strings must be "TRUE" or "FALSE" (case insensitive), but was 

What it means

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.

Solutions

  1. Pass a Boolean (true/false) instead of a String for boolean property conditions — checkValueForType maps it correctly.
  2. If a String is required, normalize it to "TRUE" or "FALSE" before calling where().
  3. Prefer Property.eq(true) helper style so the type system enforces the value.
  4. 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:

Example fix

// before
queryBuilder.where(Properties.Active.eq("true")); // throws DaoException
// after
queryBuilder.where(Properties.Active.eq(true));
// or, if a string is unavoidable:
queryBuilder.where(Properties.Active.eq(isActive ? "TRUE" : "FALSE"));
Defensive patterns

Strategy: validation

Validate before calling

function validBooleanString(v) { return v === true || v === false || /^(true|false)$/i.test(v); }
// assert validBooleanString(value) before Properties.Active.eq(value); prefer Boolean values

Type guard

function isBooleanLiteral(v) { return typeof v === 'boolean' || (typeof v === 'string' && /^(TRUE|FALSE)$/i.test(v)); }

Try / catch

try {
    queryBuilder.where(Properties.Active.eq(value)).list();
} catch (DaoException e) {
    if (e.getMessage().startsWith("Illegal boolean value")) {
        throw new IllegalArgumentException("Boolean condition value must be true/false or \"TRUE\"/\"FALSE\": " + value, e);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08). Data as JSON: /api/errors/271f930484a40dee. Report an issue: GitHub.

Appendix: source

Thrown at DaoCore/src/main/java/org/greenrobot/greendao/query/WhereCondition.java:101

                } else {
                    throw new DaoException("Illegal date value: expected java.util.Date or Long for value " + value);
                }
            } else if (property.type == boolean.class || property.type == Boolean.class) {
                if (value instanceof Boolean) {
                    return ((Boolean) value) ? 1 : 0;
                } else if (value instanceof Number) {
                    int intValue = ((Number) value).intValue();
                    if (intValue != 0 && intValue != 1) {
                        throw new DaoException("Illegal boolean value: numbers must be 0 or 1, but was " + value);
                    }
                } else if (value instanceof String) {
                    String stringValue = ((String) value);
                    if ("TRUE".equalsIgnoreCase(stringValue)) {
                        return 1;
                    } else if ("FALSE".equalsIgnoreCase(stringValue)) {
                        return 0;
                    } else {
                        throw new DaoException(
                                "Illegal boolean value: Strings must be \"TRUE\" or \"FALSE\" (case insensitive), but was "
                                        + value);
                    }
                }
            }
            return value;
        }

        private static Object[] checkValuesForType(Property property, Object[] values) {
            for (int i = 0; i < values.length; i++) {
                values[i] = checkValueForType(property, values[i]);
            }
            return values;
        }

        public final Property property;
        public final String op;

View on GitHub (pinned to 0bbb338e17)