apache/beam · error · RuntimeException

@SchemaCaseFormat can only be used on getters in Java…

Error message

@SchemaCaseFormat can only be used on getters in Java Beans. Found on setter '%s'

What it means

JavaBeanSchema validates that schema-annotation @SchemaCaseFormat appears only on getter methods. When introspecting a Java Bean, if a setter method carries @SchemaCaseFormat, the schema provider throws a RuntimeException because case-format mapping is only meaningful for reading properties into schema fields.

Solutions

  1. Move the @SchemaCaseFormat annotation from the setter to the corresponding getter method.
  2. Remove @SchemaCaseFormat from the setter if the format mapping is not needed for that property.
  3. If a write-side transformation is required, implement it manually in the setter body instead of via annotation.

Example fix

// before
public void setName(String name) { this.name = name; }
@SchemaCaseFormat(LOWER_SNAKE) public void setName2(String n) {}

// after
@SchemaCaseFormat(LOWER_SNAKE)
public String getName() { return name; }
public void setName(String name) { this.name = name; }
Defensive patterns

Strategy: validation

Validate before calling

// Java: verify annotations before registering schema
for (Method m : MyBean.class.getMethods()) {
  if (m.getName().startsWith("set") && m.isAnnotationPresent(SchemaCaseFormat.class)) {
    throw new IllegalStateException("@SchemaCaseFormat on setter: " + m.getName());
  }
}

Prevention

When it happens

Trigger: Using JavaBeanSchema as the schema provider for a class whose setter method (e.g. setFoo(String)) is annotated with @SchemaCaseFormat instead of its getter.

Common situations: Copy-pasting annotations from getter to setter, applying class-wide annotation search-and-replace, or IDE-generated setters that inherited annotations from fields/getters.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/JavaBeanSchema.java:133

                Method m =
                    Preconditions.checkNotNull(
                        t.getMethod(), JavaBeanUtils.SETTER_WITH_NULL_METHOD_ERROR);
                if (m.getAnnotation(SchemaFieldNumber.class) != null) {
                  throw new RuntimeException(
                      String.format(
                          "@SchemaFieldNumber can only be used on getters in Java Beans. Found on"
                              + " setter '%s'",
                          m.getName()));
                }
                if (m.getAnnotation(SchemaFieldName.class) != null) {
                  throw new RuntimeException(
                      String.format(
                          "@SchemaFieldName can only be used on getters in Java Beans. Found on"
                              + " setter '%s'",
                          m.getName()));
                }
                if (m.getAnnotation(SchemaCaseFormat.class) != null) {
                  throw new RuntimeException(
                      String.format(
                          "@SchemaCaseFormat can only be used on getters in Java Beans. Found on"
                              + " setter '%s'",
                          m.getName()));
                }
                return t;
              })
          .collect(Collectors.toList());
    }

    @Override
    public int hashCode() {
      return System.identityHashCode(this);
    }

    @Override
    public boolean equals(@Nullable Object obj) {
      return obj instanceof SetterTypeSupplier;

View on GitHub (pinned to 12126d8942)