{"record":{"id":"c7de2abca63914f4","repo":"redis/jedis","slug":"protocol-must-not-be-null","errorCode":null,"errorMessage":"protocol must not be null","messagePattern":"protocol must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/CommandObjects.java","lineNumber":45,"sourceCode":"import redis.clients.jedis.search.SearchProtocol.*;\nimport redis.clients.jedis.search.SearchResult.SearchResultBuilder;\nimport redis.clients.jedis.search.aggr.AggregationBuilder;\nimport redis.clients.jedis.search.aggr.AggregationResult;\nimport redis.clients.jedis.search.hybrid.FTHybridParams;\nimport redis.clients.jedis.search.hybrid.HybridResult;\nimport redis.clients.jedis.search.schemafields.SchemaField;\nimport redis.clients.jedis.timeseries.*;\nimport redis.clients.jedis.timeseries.TimeSeriesProtocol.*;\nimport redis.clients.jedis.util.KeyValue;\nimport redis.clients.jedis.util.CompareCondition;\n\npublic class CommandObjects {\n\n  private final RedisProtocol protocol;\n\n  public CommandObjects(RedisProtocol protocol) {\n    if (protocol == null) {\n      throw new IllegalArgumentException(\"protocol must not be null\");\n    }\n    this.protocol = protocol;\n  }\n\n  // TODO: remove?\n  protected RedisProtocol getProtocol() {\n    return protocol;\n  }\n\n  protected volatile CommandKeyArgumentPreProcessor keyPreProcessor = null;\n  private Lock mapperLock = new ReentrantLock(true);\n  private volatile JsonObjectMapper jsonObjectMapper;\n  private final AtomicInteger searchDialect = new AtomicInteger(SearchProtocol.DEFAULT_DIALECT);\n\n  @Experimental\n  public void setKeyArgumentPreProcessor(CommandKeyArgumentPreProcessor keyPreProcessor) {\n    this.keyPreProcessor = keyPreProcessor;\n  }","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/CommandObjects.java#L27-L63","documentation":"The CommandObjects constructor requires a non-null RedisProtocol (RESP2 or RESP3) because protocol version affects command encoding and behavior. Passing null means the client was constructed without specifying a protocol, so IllegalArgumentException is thrown at construction time.","triggerScenarios":"Constructing CommandObjects (or a client/builder that instantiates it) with a null RedisProtocol — e.g. a builder field left unset, ProtocolArgument/protocol config not initialized, or calling new CommandObjects(null) directly in custom executor/provider code.","commonSituations":"Custom UnifiedJedis subclasses or test fixtures building CommandObjects manually; a client builder whose protocol() was never called and whose default was null; reflection or DI wiring that failed to supply the protocol.","solutions":["Pass an explicit protocol, e.g. new CommandObjects(RedisProtocol.RESP3), or the protocol configured on your client.","If using a builder, call .protocol(...) or ensure the default protocol is set before build().","Guard the wiring: assert protocol != null (or default to RedisProtocol.RESP2) before constructing CommandObjects."],"exampleFix":"// before\nCommandObjects commandObjects = new CommandObjects(protocol); // protocol may be null\n// after\nRedisProtocol protocol = configuredProtocol != null ? configuredProtocol : RedisProtocol.RESP3;\nCommandObjects commandObjects = new CommandObjects(protocol);","handlingStrategy":"validation","validationCode":"RedisProtocol protocol = Optional.ofNullable(configuredProtocol).orElse(RedisProtocol.RESP3);\nCommandObjects co = new CommandObjects(protocol);","typeGuard":"static RedisProtocol requireProtocol(RedisProtocol p) {\n  if (p == null) throw new IllegalArgumentException(\"protocol must be set before building client\");\n  return p;\n}","tryCatchPattern":"try {\n  CommandObjects co = new CommandObjects(protocol);\n} catch (IllegalArgumentException e) {\n  if (\"protocol must not be null\".equals(e.getMessage())) {\n    protocol = RedisProtocol.RESP3;\n  } else throw e;\n}","preventionTips":["Always set protocol explicitly in builders and test fixtures.","Default to RedisProtocol.RESP2/RESP3 at a single config point.","Validate client configuration fields before constructing executors/CommandObjects."],"tags":["null-check","configuration","constructor"],"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"}