{"record":{"id":"b1be4f120076e4a8","repo":"apache/beam","slug":"schemafieldnumber-can-only-be-used-on-getters-in-java-beans","errorCode":null,"errorMessage":"@SchemaFieldNumber can only be used on getters in Java Beans. Found on setter '%s'","messagePattern":"@SchemaFieldNumber can only be used on getters in Java Beans\\. Found on setter '(.+?)'","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/JavaBeanSchema.java","lineNumber":119,"sourceCode":"\n  /** {@link FieldValueTypeSupplier} that's based on setter methods. */\n  @VisibleForTesting\n  public static class SetterTypeSupplier implements FieldValueTypeSupplier {\n    private static final SetterTypeSupplier INSTANCE = new SetterTypeSupplier();\n\n    @Override\n    public List<FieldValueTypeInformation> get(TypeDescriptor<?> typeDescriptor) {\n      return ReflectUtils.getMethods(typeDescriptor.getRawType()).stream()\n          .filter(ReflectUtils::isSetter)\n          .filter(m -> !m.isAnnotationPresent(SchemaIgnore.class))\n          .map(m -> FieldValueTypeInformation.forSetter(typeDescriptor, m))\n          .map(\n              t -> {\n                Method m =\n                    Preconditions.checkNotNull(\n                        t.getMethod(), JavaBeanUtils.SETTER_WITH_NULL_METHOD_ERROR);\n                if (m.getAnnotation(SchemaFieldNumber.class) != null) {\n                  throw new RuntimeException(\n                      String.format(\n                          \"@SchemaFieldNumber can only be used on getters in Java Beans. Found on\"\n                              + \" setter '%s'\",\n                          m.getName()));\n                }\n                if (m.getAnnotation(SchemaFieldName.class) != null) {\n                  throw new RuntimeException(\n                      String.format(\n                          \"@SchemaFieldName can only be used on getters in Java Beans. Found on\"\n                              + \" setter '%s'\",\n                          m.getName()));\n                }\n                if (m.getAnnotation(SchemaCaseFormat.class) != null) {\n                  throw new RuntimeException(\n                      String.format(\n                          \"@SchemaCaseFormat can only be used on getters in Java Beans. Found on\"\n                              + \" setter '%s'\",\n                          m.getName()));","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/JavaBeanSchema.java#L101-L137","documentation":"Thrown by JavaBeanSchema.get when a setter method carries @SchemaFieldNumber. In Java Beans, schema metadata annotations like @SchemaFieldNumber must appear on the getter only; placing it on the setter is rejected to prevent conflicting definitions.","triggerScenarios":"Annotating a setter (e.g. setName) with @SchemaFieldNumber; schema registration then introspects setter methods and throws this exception.","commonSituations":"Copy-pasting annotations from getters to setters; codegen generating symmetric annotations; misunderstanding that annotations belong on setters.","solutions":["Move @SchemaFieldNumber from the setter to the corresponding getter.","Remove the annotation from the setter entirely — it is ignored/invalid there by design."],"exampleFix":"// before\n@SchemaFieldNumber(0)\npublic void setName(String name) { ... }\n\n// after\npublic void setName(String name) { ... }\n// (keep @SchemaFieldNumber(0) on getName())","handlingStrategy":"validation","validationCode":"for (Method m : clazz.getMethods()) { if (m.getParameterCount() == 1 && m.isAnnotationPresent(SchemaFieldNumber.class)) { throw new IllegalStateException(\"@SchemaFieldNumber must be on the getter of \" + m.getName().substring(3)); } }","typeGuard":null,"tryCatchPattern":"try { schemaOf(clazz); } catch (RuntimeException e) { if (e.getMessage().contains(\"@SchemaFieldNumber can only be used on getters\")) { /* move annotation to getter */ } else { throw e; } }","preventionTips":["Put all schema annotations (@SchemaFieldNumber, @SchemaFieldName, @SchemaCaseFormat) on getters only.","Configure code generators to emit annotations on getters.","Scan for annotations on setters in a unit test."],"tags":["java","beam-schema","annotations","javabeans"],"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"}