{"record":{"id":"4919399e8875b9ae","repo":"greenrobot/greenDAO","slug":"illegal-date-value-expected-java-util-date-or-lon","errorCode":null,"errorMessage":"Illegal date value: expected java.util.Date or Long for value ","messagePattern":"Illegal date value: expected java\\.util\\.Date or Long for value ","errorType":"exception","errorClass":"DaoException","httpStatus":null,"severity":"error","filePath":"DaoCore/src/main/java/org/greenrobot/greendao/query/WhereCondition.java","lineNumber":84,"sourceCode":"                }\n            }\n        }\n    }\n\n    class PropertyCondition extends AbstractCondition {\n\n        private static Object checkValueForType(Property property, Object value) {\n            if (value != null && value.getClass().isArray()) {\n                throw new DaoException(\"Illegal value: found array, but simple object required\");\n            }\n            Class<?> type = property.type;\n            if (type == Date.class) {\n                if (value instanceof Date) {\n                    return ((Date) value).getTime();\n                } else if (value instanceof Long) {\n                    return value;\n                } 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 \"","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoCore/src/main/java/org/greenrobot/greendao/query/WhereCondition.java#L66-L102","documentation":"For properties typed java.util.Date, checkValueForType() accepts only a Date instance or a Long (epoch millis) and converts both to a long for storage. Any other value type (String, Integer, etc.) triggers this DaoException. The conversion exists because greenDAO stores dates as numeric timestamps.","triggerScenarios":"where(Properties.CreatedAt.eq(\"2024-01-01\")) or passing an Integer/other type to a condition on a Date-typed property.","commonSituations":"Passing dates as formatted strings from JSON/API payloads instead of parsing them to java.util.Date first.","solutions":["Parse the string to a Date first (e.g. new SimpleDateFormat(\"yyyy-MM-dd\").parse(value)) and pass the Date.","Pass epoch milliseconds as a Long instead.","Check the property type in the generated Properties class; only Date-typed properties enforce this rule."],"exampleFix":"// before\nqueryBuilder.where(UserDao.Properties.CreatedAt.eq(\"2024-01-01\")); // DaoException\n// after\nDate d = new SimpleDateFormat(\"yyyy-MM-dd\").parse(\"2024-01-01\");\nqueryBuilder.where(UserDao.Properties.CreatedAt.eq(d));","handlingStrategy":"type-guard","validationCode":"Object v = /* candidate */;\nif (!(v instanceof java.util.Date || v instanceof Long)) {\n  throw new IllegalArgumentException(\"Date property needs Date or Long\");\n}","typeGuard":"boolean isDateValue(Object v) { return v instanceof java.util.Date || v instanceof Long; }","tryCatchPattern":"try { cond = Properties.CreatedAt.eq(v); } catch (DaoException e) { cond = Properties.CreatedAt.eq(parseDate(v)); }","preventionTips":["Normalize all date inputs to java.util.Date (or epoch Long) at your data boundary.","Parse date strings from JSON/APIs before building queries.","Check the generated Properties type before binding values."],"tags":["greendao","where-condition","date","android"],"backgroundTag":"invalid-date-format","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"}