{"record":{"id":"3b575cd6dce787ca","repo":"apache/dubbo","slug":"consumer-is-not-initialized","errorCode":null,"errorMessage":"Consumer is not initialized","messagePattern":"Consumer is not initialized","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java","lineNumber":167,"sourceCode":"        List<String> prefixes = new ArrayList<>();\n        // dubbo.reference.{interface-name}\n        prefixes.add(DUBBO + \".reference.\" + interfaceName);\n        return prefixes;\n    }\n\n    @Override\n    @Transient\n    public Map<String, String> getMetaData() {\n        return getMetaData(null);\n    }\n\n    @Override\n    public Map<String, String> getMetaData(String prefix) {\n        Map<String, String> metaData = new HashMap<>();\n        ConsumerConfig consumer = this.getConsumer();\n        // consumer should be initialized at preProcessRefresh()\n        if (isRefreshed() && consumer == null) {\n            throw new IllegalStateException(\"Consumer is not initialized\");\n        }\n        // use consumer attributes as default value\n        appendAttributes(metaData, consumer, prefix);\n        appendAttributes(metaData, this, prefix);\n        return metaData;\n    }\n\n    /**\n     * Get service interface class of this reference.\n     * The actual service type of remote provider.\n     *\n     * @return\n     */\n    public Class<?> getServiceInterfaceClass() {\n        Class<?> actualInterface = interfaceClass;\n        if (interfaceClass == GenericService.class) {\n            try {\n                if (getInterfaceClassLoader() != null) {","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java#L149-L185","documentation":"Thrown by ReferenceConfigBase.getMetaData when the config has been refreshed but its ConsumerConfig is still null. The consumer should be resolved during preProcessRefresh(); if it is absent after refresh, the reference is in an inconsistent state. This usually points to missing consumer configuration or a broken refresh lifecycle.","triggerScenarios":"Calling getMetaData() on a ReferenceConfigBase that has isRefreshed() == true but getConsumer() == null. The consumer is normally set during preProcessRefresh() by looking up ConsumerConfig by consumerIds or default.","commonSituations":"Referencing a consumer id that does not exist (so it was never resolved). Refreshing the config outside the normal lifecycle that populates the consumer. Removing or renaming the ConsumerConfig after the reference was refreshed. Module/Application scope changes that orphan the consumer lookup.","solutions":["Ensure a ConsumerConfig is registered (explicitly or via dubbo.consumer.* properties) and reachable from the reference's module scope.","Verify the consumerIds on the ReferenceConfigBase point to an existing ConsumerConfig.","Re-trigger the full config refresh lifecycle rather than partial refresh so preProcessRefresh() runs."],"exampleFix":"// before\nreferenceConfig.setConsumer(null); // or consumerIds points to missing config\n\n// after\nConsumerConfig consumer = new ConsumerConfig();\nconsumer.setId(\"myConsumer\");\nconfigManager.addConsumer(consumer);\nreferenceConfig.setConsumer(consumer);","handlingStrategy":"validation","validationCode":"// Before calling getMetaData, ensure consumer is wired (if refreshed)\nif (referenceConfig.isRefreshed() && referenceConfig.getConsumer() == null) {\n    // re-resolve consumer via consumerIds or default before proceeding\n    ConsumerConfig c = moduleConfigManager\n        .getConsumer(referenceConfig.getConsumerIds())\n        .orElseThrow(() -> new IllegalStateException(\"ConsumerConfig missing\"));\n    referenceConfig.setConsumer(c);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Map<String, String> meta = referenceConfig.getMetaData();\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Consumer is not initialized\")) {\n        // re-run the refresh lifecycle or wire the consumer explicitly\n    }\n    throw e;\n}","preventionTips":["Always register a ConsumerConfig (or dubbo.consumer.* defaults) before refreshing references.","Ensure consumerIds reference existing ConsumerConfig entries.","Use the standard refresh lifecycle rather than ad-hoc refresh calls."],"tags":["reference-config","consumer","lifecycle"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}