apache/beam · error · RuntimeException
Setter has wrong prefix <method>
Error message
Setter has wrong prefix <method>
What it means
Thrown by FieldValueTypeInformation.forSetter when a method expected to be a setter does not start with the configured setterPrefix (default "set"). The prefix is stripped to derive the property name, so a mismatching name cannot be mapped.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/FieldValueTypeInformation.java:291
return forSetter(null, method);
}
public static FieldValueTypeInformation forSetter(Method method, String setterPrefix) {
return forSetter(null, method, setterPrefix);
}
public static FieldValueTypeInformation forSetter(
@Nullable TypeDescriptor<?> typeDescriptor, Method method) {
return forSetter(typeDescriptor, method, "set");
}
public static FieldValueTypeInformation forSetter(
@Nullable TypeDescriptor<?> typeDescriptor, Method method, String setterPrefix) {
String name;
if (method.getName().startsWith(setterPrefix)) {
name = ReflectUtils.stripPrefix(method.getName(), setterPrefix);
} else {
throw new RuntimeException("Setter has wrong prefix " + method.getName());
}
TypeDescriptor<?> type =
Optional.ofNullable(typeDescriptor)
.map(td -> (TypeDescriptor) td.resolveType(method.getGenericParameterTypes()[0]))
// fall back to previous behavior
.orElseGet(() -> TypeDescriptor.of(method.getGenericParameterTypes()[0]));
boolean nullable = hasSingleNullableParameter(method);
return new AutoValue_FieldValueTypeInformation.Builder()
.setName(name)
.setNullable(nullable)
.setType(type)
.setRawType(type.getRawType())
.setMethod(method)
.setElementType(getIterableComponentType(type))
.setMapKeyType(getMapKeyType(type))
.setMapValueType(getMapValueType(type))
.setOneOfTypes(Collections.emptyMap())View on GitHub (pinned to 12126d8942)
Solutions
- Rename the method to start with the setterPrefix in use (default "set").
- Pass the correct setterPrefix to JavaBeanSchema/forSetter to match the class convention (e.g. "with" for builders).
- Use @SchemaFieldName-style annotations on getters and let mapping match setters by property name.
Example fix
// before (schema uses "set" prefix)
public User withName(String name) { ... }
// after
public User setName(String name) { ... } Defensive patterns
Strategy: validation
Validate before calling
String prefix = "set"; for (Method m : clazz.getMethods()) { if (m.getParameterCount() == 1 && !m.getName().startsWith(prefix)) { /* flag non-setter single-arg methods or fix prefix */ } } Type guard
static boolean matchesSetterPrefix(Method m, String prefix) { return m.getName().startsWith(prefix) && m.getParameterCount() == 1; } Try / catch
try { schemaOf(clazz); } catch (RuntimeException e) { if (e.getMessage().startsWith("Setter has wrong prefix")) { /* align method names with setterPrefix */ } else { throw e; } } Prevention
- Use the standard "set" prefix unless intentionally configuring a custom setterPrefix.
- Ensure custom setterPrefix strings match method names exactly (case included).
- Avoid mixing builder-style withX and setX in the same schema'd class.
When it happens
Trigger: Schema registration with a custom setter prefix (e.g. "with") while methods use "set", or vice versa; passing a non-setter method to forSetter.
Common situations: Builder-style classes using withX/prefix conventions being registered with default "set" prefix; custom setterPrefix string mismatch (case or trailing characters).
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Getter has wrong prefix <method>
- Setter methods should take a single argument <method>
- @SchemaFieldNumber can only be used on getters in Java Beans
- @SchemaFieldName can only be used on getters in Java Beans.
- Could not determine array parameter type for field.
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/5c3c70eafa024035.
Report an issue: GitHub.