{"record":{"id":"dbd6416628f2c915","repo":"apache/dubbo","slug":"environment-is-inaccessible-for-frameworkmodel","errorCode":null,"errorMessage":"Environment is inaccessible for FrameworkModel","messagePattern":"Environment is inaccessible for FrameworkModel","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/rpc/model/FrameworkModel.java","lineNumber":376,"sourceCode":"        }\n    }\n\n    public ApplicationModel getInternalApplicationModel() {\n        return internalApplicationModel;\n    }\n\n    public FrameworkServiceRepository getServiceRepository() {\n        return serviceRepository;\n    }\n\n    @Override\n    protected Lock acquireDestroyLock() {\n        return destroyLock;\n    }\n\n    @Override\n    public Environment modelEnvironment() {\n        throw new UnsupportedOperationException(\"Environment is inaccessible for FrameworkModel\");\n    }\n\n    @Override\n    protected boolean checkIfClassLoaderCanRemoved(ClassLoader classLoader) {\n        return super.checkIfClassLoaderCanRemoved(classLoader)\n                && applicationModels.stream()\n                        .noneMatch(applicationModel -> applicationModel.containsClassLoader(classLoader));\n    }\n}\n","sourceCodeStart":358,"sourceCodeEnd":386,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/FrameworkModel.java#L358-L386","documentation":"ScopeModel declares the abstract method modelEnvironment() so that ApplicationModel and ModuleModel can return their Environment (ApplicationEnvironment / ModuleEnvironment). FrameworkModel deliberately overrides it to throw UnsupportedOperationException because environment-scoped resources (config, application name, etc.) only exist below the framework level — a FrameworkModel has no Environment. This is a hard contract: asking a framework-level model for an environment is a category error.","triggerScenarios":"Calling frameworkModel.modelEnvironment() directly. More often reached indirectly by generic code that iterates up the ScopeModel hierarchy calling modelEnvironment() on whichever model it holds, when that model happens to be a FrameworkModel rather than an ApplicationModel/ModuleModel.","commonSituations":"Custom SPI extensions or framework integrations that hold a ScopeModel reference obtained from getOrDefault() and assume it is always application-scoped. Code migrated from older Dubbo versions where Environment resolution behaved differently. Tests that construct a bare FrameworkModel and call environment-lookup helpers.","solutions":["Resolve the Environment from the ApplicationModel or ModuleModel instead of the FrameworkModel: use scopeModel instanceof checks or ScopeModelUtil.getApplicationModel(scopeModel).modelEnvironment().","If you only hold a ScopeModel, narrow it first: `if (scopeModel instanceof FrameworkModel) { /* fetch default application */ scopeModel = ((FrameworkModel) scopeModel).defaultApplication(); }` then call modelEnvironment().","Avoid calling modelEnvironment() on a value returned by getFrameworkModel(...); that method is guaranteed to return a FrameworkModel which cannot supply an environment."],"exampleFix":"// before\nEnvironment env = scopeModel.modelEnvironment(); // throws if scopeModel is a FrameworkModel\n\n// after\nEnvironment env = ScopeModelUtil.getApplicationModel(scopeModel).modelEnvironment();","handlingStrategy":"type-guard","validationCode":"ScopeModel scope = /* ... */;\nEnvironment env;\nif (scope instanceof ApplicationModel) {\n    env = ((ApplicationModel) scope).modelEnvironment();\n} else if (scope instanceof ModuleModel) {\n    env = ((ModuleModel) scope).modelEnvironment();\n} else if (scope instanceof FrameworkModel) {\n    env = ((FrameworkModel) scope).defaultApplication().modelEnvironment();\n} else {\n    throw new IllegalStateException(\"Unsupported scope: \" + scope);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call modelEnvironment() on a FrameworkModel; always descend to an ApplicationModel/ModuleModel first.","Resolve the application model via ScopeModelUtil.getApplicationModel(scope) before asking for its environment.","Document which ScopeModel subtype your helper requires at its boundary."],"tags":["scope-model","environment","api-misuse","framework-model"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}