greenrobot/greenDAO · error · RuntimeException
Type is already non-primitive
Error message
Type is already non-primitive
What it means
PropertyBuilder.nonPrimitiveType() is meant to mark a scalar property as a non-primitive Java type (e.g. use Long instead of long in generated code). If the property's PropertyType is not scalar, the conversion makes no sense and the generator aborts with a RuntimeException. It is a config-time sanity check: you can only 'un-primitivize' primitive-typed properties.
Solutions
- Remove the .nonPrimitiveType() call from properties that are already object/reference types
- Only apply .nonPrimitiveType() to scalar types (boolean, int, long, float, double, short, byte, char)
- Check the property's PropertyType.isScalar() before calling nonPrimitiveType()
- If the property should be primitive-typed, declare it with a scalar type first
Example fix
// before
Property name = user.addStringProperty("name").nonPrimitiveType().getProperty();
// after
Property name = user.addStringProperty("name").getProperty(); // String is already non-primitive Defensive patterns
Strategy: validation
Validate before calling
if (propertyType.isScalar()) { builder.nonPrimitiveType(); } Type guard
function isScalar(pt) { return ['boolean','int','long','float','double','short','byte','char'].includes(pt); } Try / catch
try { builder.nonPrimitiveType(); } catch (RuntimeException e) { if (e.getMessage().contains("non-primitive")) { /* skip: already object type */ } else { throw e; } } Prevention
- Only call nonPrimitiveType() on properties created with scalar addXxxProperty methods
- Centralize property-building helpers so the type is known before applying modifiers
- Read PropertyType.isScalar() docs before using nonPrimitiveType
When it happens
Trigger: Calling PropertyBuilder.nonPrimitiveType() (or the .javaDocNotNull chain equivalent) on a property whose type is already an object type, e.g. a String, byte[], or Date property that was never declared notNull/primitive.
Common situations: Copy-pasting a property declaration and adding .nonPrimitiveType() to a String property; applying a shared property-builder helper to properties of mixed types; API changes where a property previously scalar became a blob/String type.
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
- No mapping for
- Source entity has no primary key, but we need it for
- Source properties do not match target properties:
- Property type uninitialized
- 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/c831f6de1026f0b3.
Report an issue: GitHub.
Appendix: source
Thrown at DaoGenerator/src/org/greenrobot/greendao/generator/Property.java:97
"AUTOINCREMENT is only available to primary key properties of type long/Long");
}
property.pkAutoincrement = true;
return this;
}
public PropertyBuilder unique() {
property.unique = true;
return this;
}
public PropertyBuilder notNull() {
property.notNull = true;
return this;
}
public PropertyBuilder nonPrimitiveType() {
if (!property.propertyType.isScalar()) {
throw new RuntimeException("Type is already non-primitive");
}
property.nonPrimitiveType = true;
return this;
}
public PropertyBuilder index() {
Index index = new Index();
index.addProperty(property);
property.entity.addIndex(index);
return this;
}
public PropertyBuilder indexAsc(String indexNameOrNull, boolean isUnique) {
Index index = new Index();
index.addPropertyAsc(property);
if (isUnique) {
index.makeUnique();
}View on GitHub (pinned to 0bbb338e17)