{"record":{"id":"7d9b55182f202d21","repo":"apache/dubbo","slug":"the-class-getclassdesc-ref-getclass-unimpleme","errorCode":null,"errorMessage":"The class <getClassDesc(ref.getClass())> unimplemented interface <getClassDesc(interfaceClass)>!","messagePattern":"The class <getClassDesc\\(ref\\.getClass\\(\\)\\)> unimplemented interface <getClassDesc\\(interfaceClass\\)>!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java","lineNumber":154,"sourceCode":"    }\n\n    public boolean shouldDelay() {\n        Integer delay = getDelay();\n        return delay != null && delay > 0;\n    }\n\n    @Override\n    public Integer getDelay() {\n        return (delay == null && provider != null) ? provider.getDelay() : delay;\n    }\n\n    protected void checkRef() {\n        // reference should not be null, and is the implementation of the given interface\n        if (ref == null) {\n            throw new IllegalStateException(\"ref not allow null!\");\n        }\n        if (!interfaceClass.isInstance(ref)) {\n            throw new IllegalStateException(\"The class \"\n                    + getClassDesc(ref.getClass()) + \" unimplemented interface \"\n                    + getClassDesc(interfaceClass) + \"!\");\n        }\n    }\n\n    private String getClassDesc(Class clazz) {\n        ClassLoader classLoader = clazz.getClassLoader();\n        return clazz.getName() + \"[classloader=\" + classLoader.getClass().getName() + \"@\" + classLoader.hashCode()\n                + \"]\";\n    }\n\n    public Optional<String> getContextPath(ProtocolConfig protocolConfig) {\n        String contextPath = protocolConfig.getContextpath();\n        if (StringUtils.isEmpty(contextPath) && provider != null) {\n            contextPath = provider.getContextpath();\n        }\n        return Optional.ofNullable(contextPath);\n    }","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java#L136-L172","documentation":"Thrown by ServiceConfigBase.checkRef when the ref instance is not assignable to the declared interfaceClass. The implementation must be an instance of the interface the service exposes, otherwise the export is rejected.","triggerScenarios":"Calling checkRef()/export() where ref != null but interfaceClass.isInstance(ref) is false — i.e. the impl class does not implement the declared interface.","commonSituations":"Setting an interface that the implementation does not implement (mismatch between setInterface and setRef). Classloader isolation where the same interface name resolves to different class objects in different loaders. Copy-paste error wiring the wrong impl to a service. Generics erasure causing the runtime check to fail.","solutions":["Ensure the ref instance's class implements the exact interfaceClass set on the ServiceConfig.","For classloader isolation, make sure the interface class is loaded by a shared parent loader so both sides agree on identity.","Re-derive interfaceClass from the ref if appropriate, or align setInterface with the impl."],"exampleFix":"// before\nserviceConfig.setInterface(BarService.class);\nserviceConfig.setRef(new FooServiceImpl()); // does not implement BarService\n\n// after\nserviceConfig.setInterface(FooService.class);\nserviceConfig.setRef(new FooServiceImpl());","handlingStrategy":"type-guard","validationCode":"// Verify assignability before export\nClass<?> iface = serviceConfig.getInterfaceClass();\nif (!iface.isInstance(serviceConfig.getRef())) {\n    throw new IllegalStateException(serviceConfig.getRef().getClass()\n        + \" does not implement \" + iface);\n}\nserviceConfig.export();","typeGuard":"static boolean refImplementsInterface(Object ref, Class<?> iface) {\n    return ref != null && iface != null && iface.isInstance(ref);\n}","tryCatchPattern":"try {\n    serviceConfig.export();\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"unimplemented interface\")) {\n        // align the interface type with the actual ref implementation\n    }\n    throw e;\n}","preventionTips":["Derive the interface from the ref's implemented interfaces when unsure.","In multi-loader setups, load the interface via a shared parent classloader.","Add a wiring test asserting ref implements the declared interface."],"tags":["service-config","validation","interface"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}