apache/flink · error · UnsupportedOperationException

Cannot modify forwarded fields

Error message

Cannot modify forwarded fields

What it means

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.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/operators/SingleInputSemanticProperties.java:149

        @Override
        public FieldSet getForwardingTargetFields(int input, int sourceField) {
            if (input != 0) {
                throw new IndexOutOfBoundsException();
            }
            return new FieldSet(sourceField);
        }

        @Override
        public int getForwardingSourceField(int input, int targetField) {
            if (input != 0) {
                throw new IndexOutOfBoundsException();
            }
            return targetField;
        }

        @Override
        public void addForwardedField(int sourceField, int targetField) {
            throw new UnsupportedOperationException("Cannot modify forwarded fields");
        }
    }
}

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Do not call addForwardedField on AllFieldsForwardedProperties instances — if you need custom field mappings, use a plain SingleInputSemanticProperties instead.
  2. Check the runtime type before calling addForwardedField: if the object is AllFieldsForwardedProperties, skip the mutation.
  3. Use @ForwardedFields with specific positions instead of "*" if you need fine-grained control over field forwarding.
  4. Construct a new SingleInputSemanticProperties() and populate it manually rather than reusing the all-fields-forwarded instance.

Example fix

// before
SemanticProperties props = operator.getSemanticProperties();
// props may be AllFieldsForwardedProperties
((SingleInputSemanticProperties) props).addForwardedField(0, 5); // throws

// after
if (props instanceof SingleInputSemanticProperties.AllFieldsForwardedProperties) {
    // all fields already forwarded; no modification needed
} else {
    ((SingleInputSemanticProperties) props).addForwardedField(0, 5);
}
Defensive patterns

Strategy: type-guard

Validate before calling

boolean canAddForwardedField(SemanticProperties props) {
    return !(props instanceof SingleInputSemanticProperties.AllFieldsForwardedProperties);
}

Type guard

static boolean isAllFieldsForwarded(SemanticProperties props) {
    return props instanceof SingleInputSemanticProperties.AllFieldsForwardedProperties;
}

Try / catch

try {
    singleInputProps.addForwardedField(source, target);
} catch (UnsupportedOperationException e) {
    // This is an immutable AllFieldsForwardedProperties; skip modification
    log.debug("Skipping addForwardedField on immutable AllFieldsForwardedProperties");
}

Prevention

When it happens

Trigger: 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("*")).

Common situations: 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.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/6aafdbe5662e2daf. Report an issue: GitHub.