{"record":{"id":"637606c46bb5497a","repo":"apache/dubbo","slug":"the-interface-class-interfaceclass-is-not-a-inte","errorCode":null,"errorMessage":"The interface class <interfaceClass> is not a interface!","messagePattern":"The interface class <interfaceClass> is not a interface!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java","lineNumber":257,"sourceCode":"                return Class.forName(interfaceName, true, classLoader);\n            }\n        } catch (ClassNotFoundException t) {\n            throw new IllegalStateException(t.getMessage(), t);\n        }\n        return null;\n    }\n\n    @Override\n    protected void postProcessAfterScopeModelChanged(ScopeModel oldScopeModel, ScopeModel newScopeModel) {\n        super.postProcessAfterScopeModelChanged(oldScopeModel, newScopeModel);\n        if (this.consumer != null && this.consumer.getScopeModel() != getScopeModel()) {\n            this.consumer.setScopeModel(getScopeModel());\n        }\n    }\n\n    public void setInterface(Class<?> interfaceClass) {\n        if (interfaceClass != null && !interfaceClass.isInterface()) {\n            throw new IllegalStateException(\"The interface class \" + interfaceClass + \" is not a interface!\");\n        }\n        setInterface(interfaceClass == null ? null : interfaceClass.getName());\n        this.interfaceClass = interfaceClass;\n        if (getInterfaceClassLoader() == null) {\n            setInterfaceClassLoader(interfaceClass == null ? null : interfaceClass.getClassLoader());\n        } else {\n            if (interfaceClass != null) {\n                try {\n                    if (!interfaceClass.equals(\n                            Class.forName(interfaceClass.getName(), false, getInterfaceClassLoader()))) {\n                        // interfaceClass is not visible from origin classloader, override the classloader from\n                        // interfaceClass into referenceConfig\n                        setInterfaceClassLoader(interfaceClass.getClassLoader());\n                    }\n                } catch (ClassNotFoundException e) {\n                    // class not found from origin classloader, override the classloader from interfaceClass into\n                    // referenceConfig\n                    setInterfaceClassLoader(interfaceClass.getClassLoader());","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java#L239-L275","documentation":"Thrown by ReferenceConfigBase.setInterface when the provided Class is not actually a Java interface. Dubbo references (consumers) must target an interface, not a concrete or abstract class. The check rejects the assignment before storing the class.","triggerScenarios":"Calling setInterface(Class) with a class that returns false for Class.isInterface() (i.e. a concrete class, abstract class, enum, record, etc.).","commonSituations":"Pointing a ReferenceConfig at an implementation class instead of the interface. Accidentally using a concrete service class as the reference type. Generics/typing slip where a class token of the impl is passed. Migrating code that previously used a class-based API.","solutions":["Pass the interface type that the provider implements, not the implementation class.","If you genuinely need a non-interface type, reconsider the design — Dubbo references require interfaces.","Use setInterface(String) with the interface's fully-qualified name if you only have the name."],"exampleFix":"// before\nreferenceConfig.setInterface(FooServiceImpl.class); // concrete class\n\n// after\nreferenceConfig.setInterface(FooService.class); // the interface","handlingStrategy":"type-guard","validationCode":"// Ensure the class is an interface before assigning\nif (interfaceClass != null && !interfaceClass.isInterface()) {\n    throw new IllegalArgumentException(\n        interfaceClass + \" is not an interface; references require an interface type\");\n}\nreferenceConfig.setInterface(interfaceClass);","typeGuard":"static boolean isJavaInterface(Class<?> c) {\n    return c != null && c.isInterface();\n}","tryCatchPattern":"try {\n    referenceConfig.setInterface(clazz);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"is not a interface\")) {\n        // locate the interface the class implements and use that\n    }\n    throw e;\n}","preventionTips":["Always pass the service interface type, never the implementation class, to references.","When using generics, ensure the type parameter is bound to an interface."],"tags":["reference-config","validation","interface"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}