apache/beam · error · IllegalArgumentException

Type mismatch between getter and setter methods for property

Error message

Type mismatch between getter and setter methods for property [%s]. Getter is of type [%s] whereas setter is of type [%s].

What it means

PipelineOptionsFactory validates that each interface method pair (getter/setter) on a PipelineOptions subinterface has matching generic return/parameter types. When exactly one property has mismatched getter and setter types, throwForTypeMismatches throws an IllegalArgumentException naming the property and both types.

Solutions

  1. Make the setter parameter type exactly match the getter return type for the named property.
  2. Regenerate the setter using the IDE's 'generate setter' from the getter.
  3. Check the generic type parameters (e.g. Map<String, List<T>>) are identical on both methods.
  4. If both methods are intentional but different names were intended, rename the methods so they don't form a mismatched property pair.

Example fix

// before
String getOutputPath();
void setOutputPath(Path path);
// after
String getOutputPath();
void setOutputPath(String path);
Defensive patterns

Strategy: validation

Validate before calling

assert optionsIface.getMethod("getFoo").getGenericReturnType().equals(optionsIface.getMethod("setFoo", String.class).getGenericParameterTypes()[0]);

Try / catch

try { PipelineOptionsFactory.as(MyOptions.class); } catch (IllegalArgumentException e) { throw new IllegalStateException("bad options interface: " + e.getMessage(), e); }

Prevention

When it happens

Trigger: Defining a PipelineOptions interface with e.g. int getFoo() but void setFoo(String value), or a getter returning a subtype while the setter takes a supertype.

Common situations: Refactoring an option type in one method but not the other, hand-writing setters without IDE assistance, or copy-pasting option interfaces between classes.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/70698b2c32a2959e. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java:921

    // Add the remaining getters with missing setters.
    for (Map.Entry<String, Method> getterToMethod : propertyNamesToGetters.entrySet()) {
      descriptors.add(
          new PropertyDescriptor(getterToMethod.getKey(), getterToMethod.getValue(), null));
    }
    return descriptors;
  }

  private static class TypeMismatch {
    private String propertyName;
    private Type getterPropertyType;
    private Type setterPropertyType;
  }

  private static void throwForTypeMismatches(List<TypeMismatch> mismatches) {
    if (mismatches.size() == 1) {
      TypeMismatch mismatch = mismatches.get(0);
      throw new IllegalArgumentException(
          String.format(
              "Type mismatch between getter and setter methods for property [%s]. "
                  + "Getter is of type [%s] whereas setter is of type [%s].",
              mismatch.propertyName, mismatch.getterPropertyType, mismatch.setterPropertyType));
    } else if (mismatches.size() > 1) {
      StringBuilder builder =
          new StringBuilder("Type mismatches between getters and setters detected:");
      for (TypeMismatch mismatch : mismatches) {
        builder.append(
            String.format(
                "%n  - Property [%s]: Getter is of type [%s] whereas setter is of type [%s].",
                mismatch.propertyName,
                mismatch.getterPropertyType.toString(),
                mismatch.setterPropertyType.toString()));
      }
      throw new IllegalArgumentException(builder.toString());
    }
  }

View on GitHub (pinned to 12126d8942)