redis/jedis · error · IllegalStateException
Attribute for this field is already set.
Error message
Attribute for this field is already set.
What it means
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.
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()
Example fix
// before
FieldName f = new FieldName("title").as("t");
f.as("title_alias"); // throws
// after
FieldName f1 = new FieldName("title").as("t");
FieldName f2 = new FieldName("title").as("title_alias"); Defensive patterns
Strategy: type-guard
Type guard
// create a fresh instance each time instead of guarding state FieldName renamed = FieldName.of(base.getName()).as(attribute);
Prevention
- 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
When it happens
Trigger: Calling field.as("a").as("b") on the same FieldName; reusing a cached FieldName object across multiple schema definitions without creating a new instance.
Common situations: Reusing shared/static FieldName instances in index-definition builders; loops that accumulate aliases on one object; copy-paste schema code applying as() twice.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Setting null as field attribute is not allowed.
- A null argument cannot be sent to Redis.
- Unrecognized header
- DIALECT=0 cannot be set.
- HashImport ' ' has been discarded
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/9aa367039650a101.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/search/FieldName.java:27
private final String name;
private String attribute;
public FieldName(String name) {
this.name = name;
}
public FieldName(String name, String attribute) {
this.name = name;
this.attribute = attribute;
}
public FieldName as(String attribute) {
if (attribute == null) {
throw new IllegalArgumentException("Setting null as field attribute is not allowed.");
}
if (this.attribute != null) {
throw new IllegalStateException("Attribute for this field is already set.");
}
this.attribute = attribute;
return this;
}
public final String getName() {
return name;
}
public final String getAttribute() {
return attribute;
}
public int addCommandArguments(List<Object> args) {
args.add(name);
if (attribute == null) {
return 1;
}View on GitHub (pinned to 6dac31d4c2)