{"record":{"id":"b0e6f25fb3aee725","repo":"redis/jedis","slug":"hostandport-is-required-when-no-socketfactory-is-p","errorCode":null,"errorMessage":"HostAndPort is required when no socketFactory is provided","messagePattern":"HostAndPort is required when no socketFactory is provided","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/ConnectionFactory.java","lineNumber":108,"sourceCode":"      return new ConnectionFactory(this);\n    }\n\n    private Builder withDefaults() {\n      if (jedisSocketFactory == null) {\n        this.jedisSocketFactory = createDefaultSocketFactory();\n      }\n      if (connectionBuilder == null) {\n        this.connectionBuilder = createDefaultConnectionBuilder();\n      }\n      return this;\n    }\n\n    private JedisSocketFactory createDefaultSocketFactory() {\n      if (clientConfig == null) {\n        clientConfig = DefaultJedisClientConfig.builder().build();\n      }\n      if (hostAndPort == null) {\n        throw new IllegalStateException(\"HostAndPort is required when no socketFactory is provided\");\n      }\n      return new DefaultJedisSocketFactory(hostAndPort, clientConfig, maintenanceController);\n    }\n\n    private Connection.Builder createDefaultConnectionBuilder() {\n      Connection.Builder connBuilder = cache == null ? Connection.builder() : CacheConnection.builder(cache);\n      connBuilder.socketFactory(jedisSocketFactory).clientConfig(clientConfig);\n      if (maintenanceController != null) {\n        connBuilder.maintenanceConfig(maintenanceController.getConfig())\n            .addVisitor(new MaintenanceAwareVisitor(connBuilder, maintenanceController));\n      }\n      return connBuilder;\n    }\n  }\n\n  public static Builder builder() {\n    return new Builder();\n  }","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/ConnectionFactory.java#L90-L126","documentation":"ConnectionFactory.createDefaultSocketFactory() throws IllegalStateException when neither a hostAndPort nor a custom socketFactory was supplied. Without one of them the client has no target endpoint to open a socket to, so builder validation fails at build() time.","triggerScenarios":"Building a client via RedisClient/AbstractClientBuilder without calling .hostAndPort(...) while also not providing .socketFactory(...); calling withDefaults() on a builder that only set config items like timeout or password.","commonSituations":"Copy-pasted builder code where the host line was deleted or variable is null; programmatic config assembled from environment/properties where the hostname key was missing; sentinel/cluster snippets applied to standalone builders without host setup.","solutions":["Call .hostAndPort(\"localhost\", 6379) (or hostAndPort(HostAndPort)) on the builder","Provide a custom javax.net.SocketFactory via .socketFactory(...) for socket-based connections","Fix the source of the null host variable (missing env var/config property) before building"],"exampleFix":"// before\nRedisClient client = RedisClient.builder()\n    .clientConfig(cfg).build(); // IllegalStateException\n// after\nRedisClient client = RedisClient.builder()\n    .hostAndPort(\"localhost\", 6379)\n    .clientConfig(cfg).build();","handlingStrategy":"validation","validationCode":"if (hostAndPort == null && socketFactory == null) {\n  throw new IllegalArgumentException(\"Provide hostAndPort or socketFactory before build()\");\n}\nRedisClient client = RedisClient.builder().hostAndPort(host, port).build();","typeGuard":null,"tryCatchPattern":"try {\n  RedisClient client = RedisClient.builder()...build();\n} catch (IllegalStateException e) {\n  // log missing endpoint configuration and abort startup\n}","preventionTips":["Always call .hostAndPort(...) first in builder chains","Load the host from config with an explicit fail-fast check before building the client","For unix-socket setups, remember a socketFactory must be supplied instead"],"tags":["java","jedis","builder","configuration","missing-endpoint"],"backgroundTag":"missing-required-config-field","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"}