greenrobot/greenDAO · error · RuntimeException
Interface defined more than once:
Error message
Interface defined more than once:
What it means
Entity.implementsInterface rejects adding the same interface name twice to an entity's implements list. Duplicates would emit an invalid Java class declaration (implements Foo, Foo), so the generator throws a RuntimeException immediately during schema building.
Solutions
- Deduplicate the interface list before passing it to implementsInterface (e.g. new LinkedHashSet<>(Arrays.asList(...))).
- Remove redundant implementsInterface calls for interfaces already declared.
- Don't pass "Serializable" via implementsInterface when implementsSerializable() is already used.
- Guard call sites with entity.getInterfaces().contains(name) checks before adding.
Example fix
// before
entity.implementsSerializable();
entity.implementsInterface("java.io.Serializable"); // duplicate
// after
entity.implementsSerializable(); // only once Defensive patterns
Strategy: validation
Validate before calling
List<String> distinct = new ArrayList<>(new LinkedHashSet<>(Arrays.asList(interfaces))); entity.implementsInterface(distinct.toArray(new String[0]));
Try / catch
try {
entity.implementsInterface(names);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Interface defined more than once")) {
log.warn("Deduplicating interfaces for " + entity.getClassName());
return;
}
throw e;
} Prevention
- Deduplicate interface lists before passing them
- Don't call implementsInterface("Serializable") alongside implementsSerializable()
- Build interface lists from Sets, not Lists
- Check entity config for repeated base-interface declarations
When it happens
Trigger: Calling entity.implementsInterface("Comparable", "Comparable") or invoking implementsInterface multiple times with overlapping names; using both implementsSerializable() and implementsInterface("Serializable").
Common situations: Varargs call sites built from collections that may contain repeats; configuration-driven entity setup where a base config and a per-entity config both add the same interface; combining implementsSerializable() with an explicit "java.io.Serializable" entry.
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
- Property already defined:
- Duplicate name for
- No DAO registered for
- Could not init DAOConfig
- Duplicate property ordinals
AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08).
Data as JSON: /api/errors/61b5c50034f280fc.
Report an issue: GitHub.
Appendix: source
Thrown at DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java:472
return additionalImportsDao;
}
public void setHasKeepSections(Boolean hasKeepSections) {
this.hasKeepSections = hasKeepSections;
}
public List<String> getInterfacesToImplement() {
return interfacesToImplement;
}
public List<ContentProvider> getContentProviders() {
return contentProviders;
}
public void implementsInterface(String... interfaces) {
for (String interfaceToImplement : interfaces) {
if (interfacesToImplement.contains(interfaceToImplement)) {
throw new RuntimeException("Interface defined more than once: " + interfaceToImplement);
}
interfacesToImplement.add(interfaceToImplement);
}
}
public void implementsSerializable() {
interfacesToImplement.add("java.io.Serializable");
}
public String getSuperclass() {
return superclass;
}
public void setSuperclass(String classToExtend) {
this.superclass = classToExtend;
}
public String getJavaDoc() {View on GitHub (pinned to 0bbb338e17)