greenrobot/greenDAO · error · RuntimeException
Property type uninitialized
Error message
Property type uninitialized
What it means
During ToMany.init2ndPass(), the generator compares source and target property types to validate the join. A null PropertyType means the property's type was never initialized (its init2ndPass/type resolution did not run or the property was created without a type), so the comparison cannot be performed and the generator throws.
Solutions
- Create properties through Entity.addXxxProperty(...) so PropertyType is set automatically
- Ensure the referenced entities complete their own init2ndPass before the ToMany relation does
- Check that the property objects passed to addToMany/setSourceProperties belong to properly initialized entities
- Upgrade/regenerate if a greenDAO version bug left property types uninitialized
Example fix
// before
Property manual = new Property(...); // type never set
toMany.setSourceProperties(manual);
// after
Property typed = sourceEntity.addLongProperty("userId").getProperty();
toMany.setSourceProperties(typed); Defensive patterns
Strategy: validation
Validate before calling
sourceProps.forEach(p -> { if (p.getPropertyType() == null) throw new IllegalStateException("Uninitialized property in ToMany"); }); Type guard
function typesInitialized(props) { return props.every(p => p.getPropertyType() != null); } Try / catch
try { schema.generate(); } catch (RuntimeException e) { if (e.getMessage().equals("Property type uninitialized")) { auditPropertyCreation(); } else { throw e; } } Prevention
- Never construct Property objects manually; use Entity.addXxxProperty
- Ensure all entities referenced by relations are registered in the schema
- Do not reorder or bypass generator init passes in custom tooling
When it happens
Trigger: A source or target property in a ToMany relation whose getPropertyType() returns null — typically a Property constructed manually or added without a typed add<...>Property call, or generation passes executed out of order.
Common situations: Building Property objects programmatically instead of via Entity.addXxxProperty; custom generator extensions bypassing standard init passes; relation referencing a property from an entity not properly registered in the schema.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Source entity has no primary key, but we need it for
- Source properties do not match target properties:
- Type is already non-primitive
- No mapping for
- Source entity has no primary key, but we need it for
AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08).
Data as JSON: /api/errors/fb845a17b004dcf2.
Report an issue: GitHub.
Appendix: source
Thrown at DaoGenerator/src/org/greenrobot/greendao/generator/ToMany.java:70
if (pks.isEmpty()) {
throw new RuntimeException("Source entity has no primary key, but we need it for " + this);
}
sourceProperties = new Property[pks.size()];
sourceProperties = pks.toArray(sourceProperties);
}
int count = sourceProperties.length;
if (count != targetProperties.length) {
throw new RuntimeException("Source properties do not match target properties: " + this);
}
for (int i = 0; i < count; i++) {
Property sourceProperty = sourceProperties[i];
Property targetProperty = targetProperties[i];
PropertyType sourceType = sourceProperty.getPropertyType();
PropertyType targetType = targetProperty.getPropertyType();
if (sourceType == null || targetType == null) {
throw new RuntimeException("Property type uninitialized");
}
if (sourceType != targetType) {
System.err.println("Warning to-one property type does not match target key type: " + this);
}
}
}
void init3rdPass() {
super.init3rdPass();
}
}
View on GitHub (pinned to 0bbb338e17)