greenrobot/greenDAO · error · DaoException

Illegal value: found array, but simple object required

Error message

Illegal value: found array, but simple object required

What it means

WhereCondition.PropertyCondition.checkValueForType() validates the value bound to a comparison condition. Only scalar (non-array) values are allowed; if the value is a Java array, a DaoException is thrown. For IN conditions use the dedicated in(...) variants, which accept arrays/lists.

Solutions

  1. Use in()/notIn() for array/list values: where(Properties.Id.in(ids)).
  2. Pass a single scalar to eq()/gt()/lt() conditions.
  3. If a variable holds a single value that is an array due to varargs capture, extract the element first.

Example fix

// before
List<User> users = userDao.queryBuilder()
  .where(UserDao.Properties.Id.eq(ids)).list(); // array value -> DaoException
// after
List<User> users = userDao.queryBuilder()
  .where(UserDao.Properties.Id.in(ids)).list();
Defensive patterns

Strategy: validation

Validate before calling

if (value != null && value.getClass().isArray()) {
  // use Properties.X.in((Object[]) value) instead of eq
}

Type guard

boolean isScalar(Object v) { return v == null || !v.getClass().isArray() && !(v instanceof java.util.Collection); }

Try / catch

try { cond = Properties.Id.eq(v); } catch (DaoException e) { cond = Properties.Id.in((Object[]) v); }

Prevention

When it happens

Trigger: Calling where(Properties.Id.eq(idsArray)) or .notEq(arr) — any eq/lessThan/greaterThan-style condition given an array or a boxed array as the value.

Common situations: Developers intending an IN query pass an array to eq() instead of Properties.X.in(...), or Kotlin/Java interop converts a varargs call into an array argument.

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/bdb9014513f44109. Report an issue: GitHub.

Appendix: source

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

        }

        @Override
        public void appendValuesTo(List<Object> valuesTarget) {
            if (hasSingleValue) {
                valuesTarget.add(value);
            } else if (values != null) {
                for (Object value : values) {
                    valuesTarget.add(value);
                }
            }
        }
    }

    class PropertyCondition extends AbstractCondition {

        private static Object checkValueForType(Property property, Object value) {
            if (value != null && value.getClass().isArray()) {
                throw new DaoException("Illegal value: found array, but simple object required");
            }
            Class<?> type = property.type;
            if (type == Date.class) {
                if (value instanceof Date) {
                    return ((Date) value).getTime();
                } else if (value instanceof Long) {
                    return value;
                } 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);
                    }

View on GitHub (pinned to 0bbb338e17)