{"record":{"id":"fb845a17b004dcf2","repo":"greenrobot/greenDAO","slug":"property-type-uninitialized","errorCode":null,"errorMessage":"Property type uninitialized","messagePattern":"Property type uninitialized","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"DaoGenerator/src/org/greenrobot/greendao/generator/ToMany.java","lineNumber":70,"sourceCode":"            if (pks.isEmpty()) {\n                throw new RuntimeException(\"Source entity has no primary key, but we need it for \" + this);\n            }\n            sourceProperties = new Property[pks.size()];\n            sourceProperties = pks.toArray(sourceProperties);\n        }\n        int count = sourceProperties.length;\n        if (count != targetProperties.length) {\n            throw new RuntimeException(\"Source properties do not match target properties: \" + this);\n        }\n\n        for (int i = 0; i < count; i++) {\n            Property sourceProperty = sourceProperties[i];\n            Property targetProperty = targetProperties[i];\n\n            PropertyType sourceType = sourceProperty.getPropertyType();\n            PropertyType targetType = targetProperty.getPropertyType();\n            if (sourceType == null || targetType == null) {\n                throw new RuntimeException(\"Property type uninitialized\");\n            }\n            if (sourceType != targetType) {\n                System.err.println(\"Warning to-one property type does not match target key type: \" + this);\n            }\n        }\n    }\n\n    void init3rdPass() {\n        super.init3rdPass();\n    }\n\n}\n","sourceCodeStart":52,"sourceCodeEnd":83,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoGenerator/src/org/greenrobot/greendao/generator/ToMany.java#L52-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nProperty manual = new Property(...); // type never set\ntoMany.setSourceProperties(manual);\n// after\nProperty typed = sourceEntity.addLongProperty(\"userId\").getProperty();\ntoMany.setSourceProperties(typed);","handlingStrategy":"validation","validationCode":"sourceProps.forEach(p -> { if (p.getPropertyType() == null) throw new IllegalStateException(\"Uninitialized property in ToMany\"); });","typeGuard":"function typesInitialized(props) { return props.every(p => p.getPropertyType() != null); }","tryCatchPattern":"try { schema.generate(); } catch (RuntimeException e) { if (e.getMessage().equals(\"Property type uninitialized\")) { auditPropertyCreation(); } else { throw e; } }","preventionTips":["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"],"tags":["greendao","codegen","to-many","uninitialized"],"backgroundTag":"internal-invariant-violation","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"}