{"record":{"id":"7b7f6338b10ddc34","repo":"redis/jedis","slug":"setting-null-as-field-attribute-is-not-allowed","errorCode":null,"errorMessage":"Setting null as field attribute is not allowed.","messagePattern":"Setting null as field attribute is not allowed\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/search/FieldName.java","lineNumber":24,"sourceCode":"import redis.clients.jedis.search.SearchProtocol.SearchKeyword;\n\npublic class FieldName implements IParams {\n\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);","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/search/FieldName.java#L6-L42","documentation":"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.","triggerScenarios":"Calling new FieldName(\"my_field\").as(someString) where someString is null, often from a nullable config value or a map key derived dynamically.","commonSituations":"Building index schemas from configuration files where an alias key is absent; passing Optional-unwrapped nulls; framework code that forwards null attributes.","solutions":["Ensure the alias string is non-null before calling as(), e.g. throw or skip aliasing when absent","Only call as() when an alias is actually configured: if (alias != null) field.as(alias);","Validate schema configuration at startup before constructing FieldName objects"],"exampleFix":"// before\nfields.add(new FieldName(rawName).as(config.get(\"alias\")));\n// after\nString alias = config.get(\"alias\");\nFieldName f = new FieldName(rawName);\nif (alias != null) f.as(alias);\nfields.add(f);","handlingStrategy":"validation","validationCode":"if (alias != null) {\n  fieldName.as(alias);\n}","typeGuard":"Optional.ofNullable(alias).ifPresent(fieldName::as);","tryCatchPattern":null,"preventionTips":["Validate schema/alias configuration at startup","Never pass Optional.orElse(null) results into as()","Only call as() when aliasing is actually configured"],"tags":["redisearch","search","null-argument"],"backgroundTag":"null-argument","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"}