{"record":{"id":"37ba82981fa45d29","repo":"apache/flink","slug":"the-underlying-input-format-to-this-replicatinginp","errorCode":null,"errorMessage":"The underlying input format to this ReplicatingInputFormat isn't context aware","messagePattern":"The underlying input format to this ReplicatingInputFormat isn't context aware","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/io/ReplicatingInputFormat.java","lineNumber":133,"sourceCode":"\n    @Override\n    public void close() throws IOException {\n        this.replicatedIF.close();\n    }\n\n    @Override\n    public void setRuntimeContext(RuntimeContext context) {\n        if (this.replicatedIF instanceof RichInputFormat) {\n            ((RichInputFormat) this.replicatedIF).setRuntimeContext(context);\n        }\n    }\n\n    @Override\n    public RuntimeContext getRuntimeContext() {\n        if (this.replicatedIF instanceof RichInputFormat) {\n            return ((RichInputFormat) this.replicatedIF).getRuntimeContext();\n        } else {\n            throw new RuntimeException(\n                    \"The underlying input format to this ReplicatingInputFormat isn't context aware\");\n        }\n    }\n\n    @Override\n    public void openInputFormat() throws IOException {\n        if (this.replicatedIF instanceof RichInputFormat) {\n            ((RichInputFormat) this.replicatedIF).openInputFormat();\n        }\n    }\n\n    @Override\n    public void closeInputFormat() throws IOException {\n        if (this.replicatedIF instanceof RichInputFormat) {\n            ((RichInputFormat) this.replicatedIF).closeInputFormat();\n        }\n    }\n}","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/io/ReplicatingInputFormat.java#L115-L151","documentation":"Thrown by ReplicatingInputFormat.getRuntimeContext() when the wrapped input format is not a RichInputFormat. ReplicatingInputFormat broadcasts one input format across all parallel subtasks; it delegates getRuntimeContext to the wrapped format, but only RichInputFormat instances actually carry a RuntimeContext. A plain (non-rich) InputFormat has no context to return, so the call is rejected.","triggerScenarios":"A ReplicatingInputFormat wraps a non-Rich InputFormat (one that does not extend RichInputFormat), and downstream code calls getRuntimeContext() on the replicating wrapper — directly or via a RichFunction/operator that requests the context.","commonSituations":"Wrapping a third-party or legacy InputFormat that implements InputFormat directly instead of extending RichInputFormat; using broadcast/replicate() with a custom source that was not made rich; refactor that changed the wrapped format's base class.","solutions":["Make the wrapped InputFormat extend RichInputFormat (it then gets setRuntimeContext/getRuntimeContext for free).","Avoid calling getRuntimeContext on the ReplicatingInputFormat; instead obtain the context before wrapping and pass needed values explicitly.","If you control the wrapped format, register it as rich and ensure setRuntimeContext is propagated (the wrapper already does this for RichInputFormat)."],"exampleFix":"// before: wrapped format is a plain InputFormat\npublic class MyFormat implements InputFormat<...> { ... }\nnew ReplicatingInputFormat<>(new MyFormat(), ...).getRuntimeContext(); // throws\n// after: extend RichInputFormat\npublic class MyFormat extends RichInputFormat<...> { ... }","handlingStrategy":"type-guard","validationCode":"if (!(replicatedIF instanceof RichInputFormat)) {\n    throw new IllegalStateException(\n        \"Cannot use getRuntimeContext: wrapped format \" + replicatedIF.getClass()\n        + \" is not a RichInputFormat. Extend RichInputFormat to enable context access.\");\n}","typeGuard":"static RichInputFormat requireRich(InputFormat<?, ?> f) {\n    if (!(f instanceof RichInputFormat)) {\n        throw new IllegalArgumentException(\n            \"Expected RichInputFormat, got \" + f.getClass().getName());\n    }\n    return (RichInputFormat) f;\n}","tryCatchPattern":"RuntimeContext ctx;\ntry {\n    ctx = replicating.getRuntimeContext();\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"context aware\")) {\n        // obtain context another way or fail fast with guidance\n        throw new IllegalStateException(\"Wrapped format must extend RichInputFormat\", e);\n    }\n    throw e;\n}","preventionTips":["Make wrapped InputFormats extend RichInputFormat so they carry a RuntimeContext.","Avoid calling getRuntimeContext on ReplicatingInputFormat; obtain the context before wrapping.","Unit-test that the wrapped format is rich before constructing the replicating wrapper."],"tags":["input-format","runtime-context","api-misuse","broadcast"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}