{"record":{"id":"f7a19d5df2183600","repo":"apache/dubbo","slug":"ref-not-allow-null","errorCode":null,"errorMessage":"ref not allow null!","messagePattern":"ref not allow null!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java","lineNumber":151,"sourceCode":"    @Override\n    public Boolean getExport() {\n        return (export == null && provider != null) ? provider.getExport() : export;\n    }\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();","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java#L133-L169","documentation":"Thrown by ServiceConfigBase.checkRef when the service reference (ref) is null at export time. The ref is the actual implementation instance that will serve requests, so it must be non-null before the service is exported.","triggerScenarios":"Calling export()/checkRef() on a ServiceConfig whose setRef(...) was never called, or was called with null. Common with programmatic config where the bean wiring is incomplete.","commonSituations":"Forgetting to set the implementation bean on a programmatic ServiceConfig. Spring bean not yet instantiated when export runs (circular dependency or lazy-init). Annotation-based @Service on an abstract/interface with no concrete bean. Bean removed/disposed before export.","solutions":["Set the implementation instance via serviceConfig.setRef(impl) before exporting.","With @DubboService, ensure the annotated class is a concrete Spring bean that gets instantiated.","Check for circular dependencies or lazy initialization that delay bean creation past export."],"exampleFix":"// before\nServiceConfig<FooService> service = new ServiceConfig<>();\nservice.setInterface(FooService.class);\nservice.export(); // ref is null -> error\n\n// after\nservice.setRef(new FooServiceImpl());\nservice.export();","handlingStrategy":"validation","validationCode":"// Ensure ref is set before export\nif (serviceConfig.getRef() == null) {\n    throw new IllegalStateException(\n        \"Cannot export service \" + serviceConfig.getInterface() + \": implementation (ref) is null\");\n}\nserviceConfig.export();","typeGuard":null,"tryCatchPattern":"try {\n    serviceConfig.export();\n} catch (IllegalStateException e) {\n    if (\"ref not allow null!\".equals(e.getMessage())) {\n        serviceConfig.setRef(instantiateImpl(serviceConfig.getInterfaceClass()));\n        serviceConfig.export(); // retry after wiring\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always set the implementation bean before export.","With @DubboService, confirm the class is a concrete instantiable Spring bean.","Watch for lazy-init or circular-dependency delays that defer bean creation."],"tags":["service-config","validation","export"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}