{"record":{"id":"61b5c50034f280fc","repo":"greenrobot/greenDAO","slug":"interface-defined-more-than-once","errorCode":null,"errorMessage":"Interface defined more than once: ","messagePattern":"Interface defined more than once: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java","lineNumber":472,"sourceCode":"        return additionalImportsDao;\n    }\n\n    public void setHasKeepSections(Boolean hasKeepSections) {\n        this.hasKeepSections = hasKeepSections;\n    }\n\n    public List<String> getInterfacesToImplement() {\n        return interfacesToImplement;\n    }\n\n    public List<ContentProvider> getContentProviders() {\n        return contentProviders;\n    }\n\n    public void implementsInterface(String... interfaces) {\n        for (String interfaceToImplement : interfaces) {\n            if (interfacesToImplement.contains(interfaceToImplement)) {\n                throw new RuntimeException(\"Interface defined more than once: \" + interfaceToImplement);\n            }\n            interfacesToImplement.add(interfaceToImplement);\n        }\n    }\n\n    public void implementsSerializable() {\n        interfacesToImplement.add(\"java.io.Serializable\");\n    }\n\n    public String getSuperclass() {\n        return superclass;\n    }\n\n    public void setSuperclass(String classToExtend) {\n        this.superclass = classToExtend;\n    }\n\n    public String getJavaDoc() {","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java#L454-L490","documentation":"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.","triggerScenarios":"Calling entity.implementsInterface(\"Comparable\", \"Comparable\") or invoking implementsInterface multiple times with overlapping names; using both implementsSerializable() and implementsInterface(\"Serializable\").","commonSituations":"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.","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."],"exampleFix":"// before\nentity.implementsSerializable();\nentity.implementsInterface(\"java.io.Serializable\"); // duplicate\n// after\nentity.implementsSerializable(); // only once","handlingStrategy":"validation","validationCode":"List<String> distinct = new ArrayList<>(new LinkedHashSet<>(Arrays.asList(interfaces)));\nentity.implementsInterface(distinct.toArray(new String[0]));","typeGuard":null,"tryCatchPattern":"try {\n    entity.implementsInterface(names);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Interface defined more than once\")) {\n        log.warn(\"Deduplicating interfaces for \" + entity.getClassName());\n        return;\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["greendao","code-generation","duplicate"],"backgroundTag":"invalid-argument-value","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"}