redis/jedis · error · IllegalArgumentException

Setting null as field attribute is not allowed.

Error message

Setting null as field attribute is not allowed.

What it means

FieldName.as(attribute) renames a search index field (the AS clause in FT.CREATE/FT.ALTER). Passing null as the attribute name is rejected with IllegalArgumentException because a null alias has no meaning in the RediSearch protocol.

Solutions

  1. Ensure the alias string is non-null before calling as(), e.g. throw or skip aliasing when absent
  2. Only call as() when an alias is actually configured: if (alias != null) field.as(alias);
  3. Validate schema configuration at startup before constructing FieldName objects

Example fix

// before
fields.add(new FieldName(rawName).as(config.get("alias")));
// after
String alias = config.get("alias");
FieldName f = new FieldName(rawName);
if (alias != null) f.as(alias);
fields.add(f);
Defensive patterns

Strategy: validation

Validate before calling

if (alias != null) {
  fieldName.as(alias);
}

Type guard

Optional.ofNullable(alias).ifPresent(fieldName::as);

Prevention

When it happens

Trigger: Calling new FieldName("my_field").as(someString) where someString is null, often from a nullable config value or a map key derived dynamically.

Common situations: Building index schemas from configuration files where an alias key is absent; passing Optional-unwrapped nulls; framework code that forwards null attributes.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/7b7f6338b10ddc34. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/search/FieldName.java:24

import redis.clients.jedis.search.SearchProtocol.SearchKeyword;

public class FieldName implements IParams {

  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);

View on GitHub (pinned to 6dac31d4c2)