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

  1. Create properties through Entity.addXxxProperty(...) so PropertyType is set automatically
  2. Ensure the referenced entities complete their own init2ndPass before the ToMany relation does
  3. Check that the property objects passed to addToMany/setSourceProperties belong to properly initialized entities
  4. 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

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


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)