{"record":{"id":"10b9de724b2687ed","repo":"apache/dubbo","slug":"service-servicekey-target-is-null-10b9de","errorCode":null,"errorMessage":"Service[${serviceKey}]Target is NULL.","messagePattern":"Service\\[(.+?)\\]Target is NULL\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java","lineNumber":66,"sourceCode":"            ServiceDescriptor serviceDescriptor,\n            ClassLoader interfaceClassLoader) {\n        super(serviceInstance, serviceKey, serviceDescriptor, null, interfaceClassLoader);\n        if (null == serviceInstance) {\n            throw new IllegalArgumentException(\"Service[\" + serviceKey + \"]Target is NULL.\");\n        }\n\n        this.urls = new CopyOnWriteArrayList<>();\n    }\n\n    public ProviderModel(\n            String serviceKey,\n            Object serviceInstance,\n            ServiceDescriptor serviceDescriptor,\n            ServiceMetadata serviceMetadata,\n            ClassLoader interfaceClassLoader) {\n        super(serviceInstance, serviceKey, serviceDescriptor, null, serviceMetadata, interfaceClassLoader);\n        if (null == serviceInstance) {\n            throw new IllegalArgumentException(\"Service[\" + serviceKey + \"]Target is NULL.\");\n        }\n\n        initMethod(serviceDescriptor.getServiceInterfaceClass());\n        this.urls = new ArrayList<>(1);\n    }\n\n    public ProviderModel(\n            String serviceKey,\n            Object serviceInstance,\n            ServiceDescriptor serviceModel,\n            ModuleModel moduleModel,\n            ServiceMetadata serviceMetadata,\n            ClassLoader interfaceClassLoader) {\n        super(serviceInstance, serviceKey, serviceModel, moduleModel, serviceMetadata, interfaceClassLoader);\n        if (null == serviceInstance) {\n            throw new IllegalArgumentException(\"Service[\" + serviceKey + \"]Target is NULL.\");\n        }\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java#L48-L84","documentation":"The second ProviderModel constructor (5-arg with ServiceMetadata) performs the same non-null serviceInstance guard. It is the path used when a ServiceMetadata object is supplied alongside the service descriptor. As with the other constructors, a null target bean cannot back an exported provider and is rejected immediately rather than failing later during an invocation.","triggerScenarios":"Calling `new ProviderModel(serviceKey, null, serviceDescriptor, serviceMetadata, interfaceClassLoader)`. Reached when ServiceConfig carrying a ServiceMetadata exports with a ref that resolved to null.","commonSituations":"Same root causes as 362 (null service ref), but specifically when the metadata-bearing constructor is selected — typically when an integrator or framework path attaches a ServiceMetadata to the registration. Bean wiring mistakes, lazy beans, and programmatic export without setRef are the usual triggers.","solutions":["Pass a non-null service instance: ensure ServiceConfig.setRef(...) or the equivalent bean lookup returns the concrete implementation before export.","Validate the ref in your bootstrap: `Objects.requireNonNull(ref, \"ref for \" + serviceKey)` before constructing/exporting.","Fix the Spring/bean wiring so the referenced bean is instantiated and injected prior to Dubbo export."],"exampleFix":"// before\nObject ref = null; // bean lookup failed silently\nnew ProviderModel(key, ref, descriptor, metadata, loader); // throws\n\n// after\nObject ref = Objects.requireNonNull(beanFactory.getBean(implClass), \"missing impl for \" + key);\nnew ProviderModel(key, ref, descriptor, metadata, loader);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(serviceInstance, \"serviceInstance for \" + serviceKey);\nnew ProviderModel(serviceKey, serviceInstance, serviceDescriptor, serviceMetadata, interfaceClassLoader);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the ref bean is non-null before constructing the ProviderModel with ServiceMetadata.","Ensure the Spring context that owns the ServiceMetadata has refreshed and wired the impl bean.","Add an explicit null-check in your export path to surface a clearer error."],"tags":["provider","service-config","null-ref","service-metadata"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}