{"record":{"id":"b66e62ebbc88c341","repo":"apache/flink","slug":"the-broadcast-input-root-operator-may-not-be-null","errorCode":null,"errorMessage":"The broadcast input root operator may not be null.","messagePattern":"The broadcast input root operator may not be null\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/operators/AbstractUdfOperator.java","lineNumber":95,"sourceCode":"     *\n     * @return The broadcast input root operator.\n     */\n    public Map<String, Operator<?>> getBroadcastInputs() {\n        return this.broadcastInputs;\n    }\n\n    /**\n     * Binds the result produced by a plan rooted at {@code root} to a variable used by the UDF\n     * wrapped in this operator.\n     *\n     * @param root The root of the plan producing this input.\n     */\n    public void setBroadcastVariable(String name, Operator<?> root) {\n        if (name == null) {\n            throw new IllegalArgumentException(\"The broadcast input name may not be null.\");\n        }\n        if (root == null) {\n            throw new IllegalArgumentException(\n                    \"The broadcast input root operator may not be null.\");\n        }\n\n        this.broadcastInputs.put(name, root);\n    }\n\n    /**\n     * Clears all previous broadcast inputs and binds the given inputs as broadcast variables of\n     * this operator.\n     *\n     * @param inputs The {@code<name, root>} pairs to be set as broadcast inputs.\n     */\n    public <T> void setBroadcastVariables(Map<String, Operator<T>> inputs) {\n        this.broadcastInputs.clear();\n        this.broadcastInputs.putAll(inputs);\n    }\n\n    // --------------------------------------------------------------------------------------------","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/operators/AbstractUdfOperator.java#L77-L113","documentation":"Thrown by AbstractUdfOperator.setBroadcastVariable(String name, Operator<?> root) when the root operator argument is null. The root defines the data-producing sub-plan for the broadcast variable; a null root would leave the broadcast input dangling with no data source, so the API rejects it immediately.","triggerScenarios":"Calling setBroadcastVariable(\"myName\", null) directly, or passing an operator that was retrieved from a collection or plan traversal that returned null (e.g., an unconnected input port or an optional plan element that was never set).","commonSituations":"Internal plan construction code that wires broadcast variables programmatically where the source operator has not yet been created. In the high-level API this is guarded earlier (withBroadcastSet requires a non-null DataSet), so this is mainly seen in low-level or test code.","solutions":["Ensure the broadcast source operator is created and non-null before calling setBroadcastVariable().","Trace the null: if the root comes from a getFirstInput()/getSecondInput() or plan traversal, check why that upstream operator is unset.","Use the high-level withBroadcastSet(DataSet, name) API which guarantees a non-null data source."],"exampleFix":"// before\nOperator<?> root = maybeNullLookup();\nop.setBroadcastVariable(\"bc\", root);\n// after\nOperator<?> root = maybeNullLookup();\nif (root == null) {\n    throw new IllegalStateException(\"Broadcast source for 'bc' was not created\");\n}\nop.setBroadcastVariable(\"bc\", root);","handlingStrategy":"validation","validationCode":"if (root == null) {\n    throw new IllegalArgumentException(\"Broadcast source operator must not be null\");\n}\nop.setBroadcastVariable(name, root);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the broadcast source operator is fully constructed before calling setBroadcastVariable().","Use the high-level withBroadcastSet(DataSet, name) API which guarantees non-null input.","Add null checks in plan-building code that wires broadcast variables programmatically."],"tags":["broadcast-variable","null-check","flink-core","internal-api"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}