{"record":{"id":"9aa367039650a101","repo":"redis/jedis","slug":"attribute-for-this-field-is-already-set","errorCode":null,"errorMessage":"Attribute for this field is already set.","messagePattern":"Attribute for this field is already set\\.","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/search/FieldName.java","lineNumber":27,"sourceCode":"\n  private final String name;\n  private String attribute;\n\n  public FieldName(String name) {\n    this.name = name;\n  }\n\n  public FieldName(String name, String attribute) {\n    this.name = name;\n    this.attribute = attribute;\n  }\n\n  public FieldName as(String attribute) {\n    if (attribute == null) {\n      throw new IllegalArgumentException(\"Setting null as field attribute is not allowed.\");\n    }\n    if (this.attribute != null) {\n      throw new IllegalStateException(\"Attribute for this field is already set.\");\n    }\n    this.attribute = attribute;\n    return this;\n  }\n\n  public final String getName() {\n    return name;\n  }\n\n  public final String getAttribute() {\n    return attribute;\n  }\n\n  public int addCommandArguments(List<Object> args) {\n    args.add(name);\n    if (attribute == null) {\n      return 1;\n    }","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/search/FieldName.java#L9-L45","documentation":"A FieldName instance may only be given one attribute/alias. Calling as() a second time throws IllegalStateException because the attribute was already set, preventing silent overwrite of an earlier alias.","triggerScenarios":"Calling field.as(\"a\").as(\"b\") on the same FieldName; reusing a cached FieldName object across multiple schema definitions without creating a new instance.","commonSituations":"Reusing shared/static FieldName instances in index-definition builders; loops that accumulate aliases on one object; copy-paste schema code applying as() twice.","solutions":["Create a new FieldName for each distinct attribute mapping","Call as() exactly once per FieldName instance","If reuse is intended, clone/reset: build FieldName.from( existing ) fresh before calling as()"],"exampleFix":"// before\nFieldName f = new FieldName(\"title\").as(\"t\");\nf.as(\"title_alias\"); // throws\n// after\nFieldName f1 = new FieldName(\"title\").as(\"t\");\nFieldName f2 = new FieldName(\"title\").as(\"title_alias\");","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// create a fresh instance each time instead of guarding state\nFieldName renamed = FieldName.of(base.getName()).as(attribute);","tryCatchPattern":null,"preventionTips":["Never cache and reuse FieldName instances across schema builds","Call as() at most once per instance","Use FieldName.from()/of() to copy when a second alias is needed"],"tags":["redisearch","search","illegal-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}