apache/beam · error · RuntimeException

Java Bean ' ' contains a setter for field ' ' that has a…

Error message

Java Bean '%s' contains a setter for field '%s' that has a mismatching type. %s

What it means

validateJavaBean compares each getter's inferred type with the corresponding setter's parameter type. If they differ, Beam cannot round-trip the property through a schema field and throws RuntimeException. Consistent getter/setter types are required for a valid schema-backed bean.

Solutions

  1. Make the setter parameter type exactly match the getter return type.
  2. If the setter intentionally accepts a wider type, narrow it or add a matching-typed setter.
  3. Regenerate accessors with Lombok (@Data) so they are consistent.
  4. Check that generic types are concrete — resolve type variables to fixed classes.

Example fix

// before
public String getName() {...} public void setName(CharSequence n) {...}
// after
public String getName() {...} public void setName(String n) {...}
Defensive patterns

Strategy: validation

Validate before calling

for (PropertyDescriptor pd : Introspector.getBeanInfo(MyBean.class).getPropertyDescriptors()) { if (pd.getReadMethod() != null && pd.getWriteMethod() != null && !pd.getReadMethod().getReturnType().equals(pd.getWriteMethod().getParameterTypes()[0])) throw new IllegalStateException(pd.getName() + " accessor types differ"); }

Try / catch

try { Schema.of(MyBean.class); } catch (RuntimeException e) { if (e.getMessage().contains("mismatching type")) { /* align getter/setter types */ } throw e; }

Prevention

When it happens

Trigger: Getter returns String but setter takes CharSequence/Object; getter returns int but setter takes Integer; generic getter returning T with a setter of a concrete type; differing nullability wrappers in types Beam resolves distinctly.

Common situations: Hand-written beans where a refactor changed only one of getter/setter; Lombok generating a setter type different from a hand-written getter (e.g. fluent builder setters returning this); boxing mismatches (Integer vs int usually OK, but boxed vs unboxed logical types are not).

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/0a4351baa201326b. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/JavaBeanUtils.java:116

      Integer integer = i;
      if (setterMap.put(schema.getField(integer).getName(), setters.get(integer)) != null) {
        throw new IllegalStateException("Duplicate key");
      }
    }

    for (FieldValueTypeInformation type : getters) {
      FieldValueTypeInformation setterType = setterMap.get(type.getName());
      Method m =
          Preconditions.checkArgumentNotNull(type.getMethod(), GETTER_WITH_NULL_METHOD_ERROR);
      if (setterType == null) {
        throw new RuntimeException(
            String.format(
                "Java Bean '%s' contains a getter for field '%s', but does not contain a matching"
                    + " setter. %s",
                m.getDeclaringClass(), type.getName(), CONSTRUCTOR_HELP_STRING));
      }
      if (!type.getType().equals(setterType.getType())) {
        throw new RuntimeException(
            String.format(
                "Java Bean '%s' contains a setter for field '%s' that has a mismatching type. %s",
                m.getDeclaringClass(), type.getName(), CONSTRUCTOR_HELP_STRING));
      }
      if (!type.isNullable() == setterType.isNullable()) {
        throw new RuntimeException(
            String.format(
                "Java Bean '%s' contains a setter for field '%s' that has a mismatching nullable"
                    + " attribute. %s",
                m.getDeclaringClass(), type.getName(), CONSTRUCTOR_HELP_STRING));
      }
    }
  }

  // Static ByteBuddy instance used by all helpers.
  private static final ByteBuddy BYTE_BUDDY = new ByteBuddy();

  private static final Map<TypeDescriptorWithSchema<?>, List<FieldValueTypeInformation>>

View on GitHub (pinned to 12126d8942)