apache/beam · error · RuntimeException

Java Bean ' ' contains a getter for field ' ', but does not…

Error message

Java Bean '%s' contains a getter for field '%s', but does not contain a matching setter. %s

What it means

JavaBeanUtils.validateJavaBean checks that for every getter in a Java Bean used as a schema type there is a matching setter with the same name. A getter without a setter means Beam could build a schema but could not populate instances from rows, so it throws RuntimeException. CONSTRUCTOR_HELP_STRING suggests adding a suitable constructor for defaults.

Solutions

  1. Add a setter matching the getter name and type (setFoo for getFoo).
  2. If the property should be read-only, exclude it from the schema (e.g. use @SchemaFieldNumber/ignore annotations per the schema provider, or remove the getter).
  3. With Lombok add @Setter (or @Data) to the class.
  4. If the value should be fixed, provide a constructor so Beam can create instances via constructor injection instead of setters.

Example fix

// before
public class User { private String name; public String getName() { return name; } }
// after
public class User { private String name; public String getName() { return name; } public void setName(String n) { this.name = n; } }
Defensive patterns

Strategy: validation

Validate before calling

for (Method g : MyBean.class.getMethods()) if (isGetter(g)) { try { MyBean.class.getMethod("set" + cap(prop(g)), g.getReturnType()); } catch (NoSuchMethodException e) { throw new IllegalStateException("Missing setter for " + prop(g)); } }

Try / catch

try { Schema.of(MyBean.class); } catch (RuntimeException e) { if (e.getMessage().contains("does not contain a matching")) { /* add setter or drop getter */ } throw e; }

Prevention

When it happens

Trigger: Registering a bean class with a read-only property (getter, no setter); getter/setter naming mismatch (getX vs setVal); setter present but named differently from the getter.

Common situations: Immutable-style beans with only getters used with JavaBeanSchema; Lombok @Getter without @Setter (or vice versa); hand-written beans with typo'd setter names; adding a getter for a derived/computed field with no setter.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

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

      List<FieldValueTypeInformation> getters,
      List<FieldValueTypeInformation> setters,
      Schema schema) {

    Map<String, FieldValueTypeInformation> setterMap = new HashMap<>();
    int bound = schema.getFieldCount();
    for (int i = 0; i < bound; i++) {
      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));
      }

View on GitHub (pinned to 12126d8942)