{"record":{"id":"1dee4537365779db","repo":"apache/beam","slug":"cannot-define-both-schemafieldname-and-schemacaseformat-from","errorCode":null,"errorMessage":"Cannot define both @SchemaFieldName and @SchemaCaseFormat. From member '%s'.","messagePattern":"Cannot define both @SchemaFieldName and @SchemaCaseFormat\\. From member '(.+?)'\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/FieldValueTypeInformation.java","lineNumber":169,"sourceCode":"  }\n\n  public static <T extends AnnotatedElement & Member> int getNumberOverride(int index, T member) {\n    @Nullable SchemaFieldNumber fieldNumber = member.getAnnotation(SchemaFieldNumber.class);\n    if (fieldNumber == null) {\n      return index;\n    }\n    return Integer.parseInt(fieldNumber.value());\n  }\n\n  public static <T extends AnnotatedElement & Member> String getNameOverride(\n      String original, T member) {\n    @Nullable SchemaFieldName fieldName = member.getAnnotation(SchemaFieldName.class);\n    @Nullable SchemaCaseFormat caseFormatAnnotation = member.getAnnotation(SchemaCaseFormat.class);\n    @Nullable SchemaCaseFormat classCaseFormatAnnotation =\n        member.getDeclaringClass().getAnnotation(SchemaCaseFormat.class);\n    if (fieldName != null) {\n      if (caseFormatAnnotation != null) {\n        throw new RuntimeException(\n            String.format(\n                \"Cannot define both @SchemaFieldName and @SchemaCaseFormat. From member '%s'.\",\n                member.getName()));\n      }\n      return fieldName.value();\n    } else if (caseFormatAnnotation != null) {\n      return CaseFormat.LOWER_CAMEL.to(caseFormatAnnotation.value(), original);\n    } else if (classCaseFormatAnnotation != null) {\n      return CaseFormat.LOWER_CAMEL.to(classCaseFormatAnnotation.value(), original);\n    } else {\n      return original;\n    }\n  }\n\n  public static <T extends AnnotatedElement & Member> @Nullable String getFieldDescription(\n      T member) {\n    @Nullable SchemaFieldDescription fieldDescription =\n        member.getAnnotation(SchemaFieldDescription.class);","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/FieldValueTypeInformation.java#L151-L187","documentation":"Thrown by getNameOverride while resolving a schema field's name: a class member is annotated with both @SchemaFieldName and @SchemaCaseFormat (on the member itself), which is contradictory — one specifies an explicit name and the other specifies a case transform for the derived name. Beam rejects the ambiguous configuration.","triggerScenarios":"Annotating a getter/setter/field with both @SchemaFieldName(\"x\") and @SchemaCaseFormat(CaseFormat.LOWER_CAMEL); schema introspection of the class then throws from getNameOverride via forField/forGetter.","commonSituations":"Copy-paste annotations during refactors; mixing naming conventions on the same field after team-wide renaming; Lombok or codegen emitting both annotations.","solutions":["Remove @SchemaCaseFormat from the member and keep @SchemaFieldName with the exact desired name.","Or remove @SchemaFieldName and let @SchemaCaseFormat transform the member's Java name.","If class-level @SchemaCaseFormat is intended, only the member-level @SchemaFieldName conflicts — keep the member annotation and delete the redundant member-level case format."],"exampleFix":"// before\n@SchemaFieldName(\"user_id\")\n@SchemaCaseFormat(CaseFormat.LOWER_SNAKE)\nprivate String getUserId();\n\n// after\n@SchemaFieldName(\"user_id\")\nprivate String getUserId();","handlingStrategy":"validation","validationCode":"for (Method m : clazz.getDeclaredMethods()) { if (m.isAnnotationPresent(SchemaFieldName.class) && m.isAnnotationPresent(SchemaCaseFormat.class)) { throw new IllegalStateException(\"Member \" + m.getName() + \" has both @SchemaFieldName and @SchemaCaseFormat\"); } }","typeGuard":null,"tryCatchPattern":"try { Schema.of(clazz); } catch (RuntimeException e) { if (e.getMessage().contains(\"Cannot define both @SchemaFieldName and @SchemaCaseFormat\")) { /* remove one annotation */ } else { throw e; } }","preventionTips":["Pick one naming mechanism per member: explicit name OR case format.","Apply @SchemaCaseFormat at class level for uniform conventions.","Add an ArchUnit/test scan asserting no member has both annotations."],"tags":["java","beam-schema","annotations","conflict"],"backgroundTag":"mutually-exclusive-options","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"}