{"record":{"id":"39b08dcedad59b74","repo":"apache/flink","slug":"do-not-support-external-resource-in-current-enviro","errorCode":null,"errorMessage":"Do not support external resource in current environment","messagePattern":"Do not support external resource in current environment","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/functions/util/RuntimeUDFContext.java","lineNumber":146,"sourceCode":"        Object o = this.initializedBroadcastVars.get(name);\n        if (o != null) {\n            return (C) o;\n        } else {\n            List<T> uninitialized = (List<T>) this.uninitializedBroadcastVars.remove(name);\n            if (uninitialized != null) {\n                C result = initializer.initializeBroadcastVariable(uninitialized);\n                this.initializedBroadcastVars.put(name, result);\n                return result;\n            } else {\n                throw new IllegalArgumentException(\n                        \"The broadcast variable with name '\" + name + \"' has not been set.\");\n            }\n        }\n    }\n\n    @Override\n    public Set<ExternalResourceInfo> getExternalResourceInfos(String resourceName) {\n        throw new UnsupportedOperationException(\n                \"Do not support external resource in current environment\");\n    }\n\n    // --------------------------------------------------------------------------------------------\n\n    public void setBroadcastVariable(String name, List<?> value) {\n        this.uninitializedBroadcastVars.put(name, value);\n        this.initializedBroadcastVars.remove(name);\n    }\n\n    public void clearBroadcastVariable(String name) {\n        this.uninitializedBroadcastVars.remove(name);\n        this.initializedBroadcastVars.remove(name);\n    }\n\n    public void clearAllBroadcastVariables() {\n        this.uninitializedBroadcastVars.clear();\n        this.initializedBroadcastVars.clear();","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/functions/util/RuntimeUDFContext.java#L128-L164","documentation":"RuntimeUDFContext is a standalone RuntimeContext implementation used by the CollectionExecutor (the local in-memory/DataSet batch executor). It does not wire up an ExternalResourceInfoProvider, so its getExternalResourceInfos(resourceName) unconditionally throws UnsupportedOperationException. External resources (e.g. GPU device info) are only resolvable by the real distributed/streaming runtime contexts (StreamingRuntimeContext, DistributedRuntimeUDFContext), which delegate to an ExternalResourceInfoProvider populated from the TaskManager's configured external resources.","triggerScenarios":"Calling getRuntimeContext().getExternalResourceInfos(name) from inside a function (e.g. a RichMapFunction or the GPU streaming example MatrixVectorMul) while the job is executed via CollectionEnvironment / LocalEnvironment batch execution, or via ExecutionEnvironment.createCollectionsEnvironment(). Also hit in unit tests that construct a RuntimeUDFContext directly and exercise a function that queries external resources.","commonSituations":"Running GPU/accelerator-using jobs locally or in a test with ExecutionEnvironment that resolves to CollectionExecutor; porting a streaming GPU function to the legacy DataSet API; writing a unit test that manually builds RuntimeUDFContext instead of StreamingRuntimeContext.","solutions":["Run the job on a real streaming execution environment (StreamExecutionEnvironment) or a real cluster so the RuntimeContext is a StreamingRuntimeContext backed by a configured ExternalResourceInfoProvider.","If this is a unit test, construct StreamingRuntimeContext (or mock RuntimeContext) with an ExternalResourceInfoProvider instead of RuntimeUDFContext.","Configure the external resource on the TaskManager (external-resources entry in flink-conf.yaml) so the provider actually returns resource info.","Guard the call by checking the execution mode / runtime context type before invoking getExternalResourceInfos."],"exampleFix":"// before (fails under CollectionExecutor)\nSet<ExternalResourceInfo> info = getRuntimeContext().getExternalResourceInfos(resourceName);\n\n// after: only query when the real runtime supports it\nRuntimeContext ctx = getRuntimeContext();\nif (ctx instanceof StreamingRuntimeContext) {\n    Set<ExternalResourceInfo> info = ctx.getExternalResourceInfos(resourceName);\n    // use GPU info\n} else {\n    // fallback or fail-fast with a clear message\n}","handlingStrategy":"validation","validationCode":"// Validate runtime context type supports external resources before calling.\nRuntimeContext ctx = getRuntimeContext();\nboolean supportsExt = (ctx instanceof StreamingRuntimeContext)\n        || (ctx instanceof DistributedRuntimeUDFContext);\nif (!supportsExt) {\n    // skip accelerator code path or fail with a clear message\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run accelerator-dependent jobs on StreamExecutionEnvironment, not CollectionEnvironment.","In unit tests, inject a StreamingRuntimeContext with a configured ExternalResourceInfoProvider.","Configure external resources in flink-conf.yaml (external-resources) so the provider is populated."],"tags":["external-resource","gpu","runtime-context","unsupported-operation","local-execution"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}