apache/beam · error · RuntimeException

Setter methods should take a single argument <method>

Error message

Setter methods should take a single argument <method>

What it means

Thrown by hasSingleNullableParameter (reached via nullable()) when a Method treated as a setter does not take exactly one parameter. JavaBean setters must accept a single argument whose type matches the property.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/FieldValueTypeInformation.java:255

    return annotations.anyMatch(FieldValueTypeInformation::isNullableAnnotation);
  }

  /**
   * If the method or its return type are annotated with any variant of Nullable, then the schema
   * field is nullable.
   */
  private static boolean hasNullableReturnType(Method method) {
    Stream<Annotation> annotations =
        Stream.concat(
            Stream.of(method.getAnnotations()),
            Stream.of(method.getAnnotatedReturnType().getAnnotations()));

    return annotations.anyMatch(FieldValueTypeInformation::isNullableAnnotation);
  }

  private static boolean hasSingleNullableParameter(Method method) {
    if (method.getParameterCount() != 1) {
      throw new RuntimeException(
          "Setter methods should take a single argument " + method.getName());
    }

    Stream<Annotation> annotations =
        Stream.concat(
            Arrays.stream(method.getAnnotatedParameterTypes()[0].getAnnotations()),
            Arrays.stream(method.getParameterAnnotations()[0]));

    return annotations.anyMatch(FieldValueTypeInformation::isNullableAnnotation);
  }

  /** Try to accept any Nullable annotation. */
  private static boolean isNullableAnnotation(Annotation annotation) {
    return annotation.annotationType().getSimpleName().equals("Nullable");
  }

  public static FieldValueTypeInformation forSetter(Method method) {
    return forSetter(null, method);

View on GitHub (pinned to 12126d8942)

Solutions

  1. Change the setter to accept exactly one parameter.
  2. If extra parameters are needed, keep a single-argument setter that delegates to the richer method.
  3. Exclude the non-conforming method from schema field discovery.

Example fix

// before
public void setName(String name, int version) { ... }

// after
public void setName(String name) { ... }
Defensive patterns

Strategy: validation

Validate before calling

for (Method m : clazz.getMethods()) { if (m.getName().startsWith("set") && m.getParameterCount() != 1) { throw new IllegalStateException("Setter " + m.getName() + " must take exactly one parameter"); } }

Type guard

static boolean isBeanSetter(Method m) { return m.getParameterCount() == 1 && m.getName().startsWith("set"); }

Try / catch

try { schemaOf(clazz); } catch (RuntimeException e) { if (e.getMessage().startsWith("Setter methods should take a single argument")) { /* fix setter signature */ } else { throw e; } }

Prevention

When it happens

Trigger: Calling nullable() (or setter introspection) on a zero-arg or multi-arg method; registering a bean whose setter has extra parameters (e.g. index or context arguments).

Common situations: Builder-style withers with additional arguments; overloaded setters; generated code where setters carry metadata parameters.

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