{"record":{"id":"2184981490010090","repo":"apache/beam","slug":"setter-methods-should-take-a-single-argument-method","errorCode":null,"errorMessage":"Setter methods should take a single argument <method>","messagePattern":"Setter methods should take a single argument <method>","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/FieldValueTypeInformation.java","lineNumber":255,"sourceCode":"    return annotations.anyMatch(FieldValueTypeInformation::isNullableAnnotation);\n  }\n\n  /**\n   * If the method or its return type are annotated with any variant of Nullable, then the schema\n   * field is nullable.\n   */\n  private static boolean hasNullableReturnType(Method method) {\n    Stream<Annotation> annotations =\n        Stream.concat(\n            Stream.of(method.getAnnotations()),\n            Stream.of(method.getAnnotatedReturnType().getAnnotations()));\n\n    return annotations.anyMatch(FieldValueTypeInformation::isNullableAnnotation);\n  }\n\n  private static boolean hasSingleNullableParameter(Method method) {\n    if (method.getParameterCount() != 1) {\n      throw new RuntimeException(\n          \"Setter methods should take a single argument \" + method.getName());\n    }\n\n    Stream<Annotation> annotations =\n        Stream.concat(\n            Arrays.stream(method.getAnnotatedParameterTypes()[0].getAnnotations()),\n            Arrays.stream(method.getParameterAnnotations()[0]));\n\n    return annotations.anyMatch(FieldValueTypeInformation::isNullableAnnotation);\n  }\n\n  /** Try to accept any Nullable annotation. */\n  private static boolean isNullableAnnotation(Annotation annotation) {\n    return annotation.annotationType().getSimpleName().equals(\"Nullable\");\n  }\n\n  public static FieldValueTypeInformation forSetter(Method method) {\n    return forSetter(null, method);","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/FieldValueTypeInformation.java#L237-L273","documentation":"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.","triggerScenarios":"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).","commonSituations":"Builder-style withers with additional arguments; overloaded setters; generated code where setters carry metadata parameters.","solutions":["Change the setter to accept exactly one parameter.","If extra parameters are needed, keep a single-argument setter that delegates to the richer method.","Exclude the non-conforming method from schema field discovery."],"exampleFix":"// before\npublic void setName(String name, int version) { ... }\n\n// after\npublic void setName(String name) { ... }","handlingStrategy":"validation","validationCode":"for (Method m : clazz.getMethods()) { if (m.getName().startsWith(\"set\") && m.getParameterCount() != 1) { throw new IllegalStateException(\"Setter \" + m.getName() + \" must take exactly one parameter\"); } }","typeGuard":"static boolean isBeanSetter(Method m) { return m.getParameterCount() == 1 && m.getName().startsWith(\"set\"); }","tryCatchPattern":"try { schemaOf(clazz); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Setter methods should take a single argument\")) { /* fix setter signature */ } else { throw e; } }","preventionTips":["Keep setters single-argument per JavaBean spec.","Move multi-argument initialization to constructors or builders.","Lint generated code for setter signatures."],"tags":["java","javabeans","beam-schema","setter"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}