{"record":{"id":"6aafdbe5662e2daf","repo":"apache/flink","slug":"cannot-modify-forwarded-fields","errorCode":null,"errorMessage":"Cannot modify forwarded fields","messagePattern":"Cannot modify forwarded fields","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/operators/SingleInputSemanticProperties.java","lineNumber":149,"sourceCode":"        @Override\n        public FieldSet getForwardingTargetFields(int input, int sourceField) {\n            if (input != 0) {\n                throw new IndexOutOfBoundsException();\n            }\n            return new FieldSet(sourceField);\n        }\n\n        @Override\n        public int getForwardingSourceField(int input, int targetField) {\n            if (input != 0) {\n                throw new IndexOutOfBoundsException();\n            }\n            return targetField;\n        }\n\n        @Override\n        public void addForwardedField(int sourceField, int targetField) {\n            throw new UnsupportedOperationException(\"Cannot modify forwarded fields\");\n        }\n    }\n}\n","sourceCodeStart":131,"sourceCodeEnd":153,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/operators/SingleInputSemanticProperties.java#L131-L153","documentation":"Thrown by SingleInputSemanticProperties.AllFieldsForwardedProperties.addForwardedField() which always throws UnsupportedOperationException. AllFieldsForwardedProperties is an immutable subclass that represents the semantic property 'all input fields are forwarded to their identical output positions' — it cannot be modified with individual field mappings because it already covers every field.","triggerScenarios":"Calling addForwardedField() on an instance of AllFieldsForwardedProperties, which is typically created internally by the optimizer or compiler when a function is annotated to forward all fields (e.g., @ForwardedFields(\"*\")).","commonSituations":"Framework-internal code or custom optimizer extensions that receive an AllFieldsForwardedProperties instance (from getSemanticProperties() on a function annotated with @ForwardedFields(\"*\")) and then attempt to add additional field mappings. User code rarely triggers this directly.","solutions":["Do not call addForwardedField on AllFieldsForwardedProperties instances — if you need custom field mappings, use a plain SingleInputSemanticProperties instead.","Check the runtime type before calling addForwardedField: if the object is AllFieldsForwardedProperties, skip the mutation.","Use @ForwardedFields with specific positions instead of \"*\" if you need fine-grained control over field forwarding.","Construct a new SingleInputSemanticProperties() and populate it manually rather than reusing the all-fields-forwarded instance."],"exampleFix":"// before\nSemanticProperties props = operator.getSemanticProperties();\n// props may be AllFieldsForwardedProperties\n((SingleInputSemanticProperties) props).addForwardedField(0, 5); // throws\n\n// after\nif (props instanceof SingleInputSemanticProperties.AllFieldsForwardedProperties) {\n    // all fields already forwarded; no modification needed\n} else {\n    ((SingleInputSemanticProperties) props).addForwardedField(0, 5);\n}","handlingStrategy":"type-guard","validationCode":"boolean canAddForwardedField(SemanticProperties props) {\n    return !(props instanceof SingleInputSemanticProperties.AllFieldsForwardedProperties);\n}","typeGuard":"static boolean isAllFieldsForwarded(SemanticProperties props) {\n    return props instanceof SingleInputSemanticProperties.AllFieldsForwardedProperties;\n}","tryCatchPattern":"try {\n    singleInputProps.addForwardedField(source, target);\n} catch (UnsupportedOperationException e) {\n    // This is an immutable AllFieldsForwardedProperties; skip modification\n    log.debug(\"Skipping addForwardedField on immutable AllFieldsForwardedProperties\");\n}","preventionTips":["Check instanceof AllFieldsForwardedProperties before calling addForwardedField.","Prefer creating a fresh SingleInputSemanticProperties if you need custom field mappings.","Avoid using @ForwardedFields(\"*\") if downstream code expects to modify the properties."],"tags":["semantic-properties","immutable","unsupported-operation","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}