{"record":{"id":"bc9732b5c7f67d0a","repo":"alibaba/Sentinel","slug":"no-port-present","errorCode":null,"errorMessage":"No port present.","messagePattern":"No port present\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sentinel-extension/sentinel-datasource-redis/src/main/java/com/alibaba/csp/sentinel/datasource/redis/config/RedisHostAndPort.java","lineNumber":75,"sourceCode":"     * @return {@literal true} if has a port.\n     */\n    public boolean hasPort() {\n        return port != NO_PORT;\n    }\n\n    /**\n     * @return the host text.\n     */\n    public String getHost() {\n        return host;\n    }\n\n    /**\n     * @return the port.\n     */\n    public int getPort() {\n        if (!hasPort()) {\n            throw new IllegalStateException(\"No port present.\");\n        }\n        return port;\n    }\n\n    @Override\n    public boolean equals(Object o) {\n        if (this == o) {\n            return true;\n        }\n        if (!(o instanceof RedisHostAndPort)) {\n            return false;\n        }\n        RedisHostAndPort that = (RedisHostAndPort)o;\n        return port == that.port && (host != null ? host.equals(that.host) : that.host == null);\n    }\n\n    @Override\n    public int hashCode() {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-extension/sentinel-datasource-redis/src/main/java/com/alibaba/csp/sentinel/datasource/redis/config/RedisHostAndPort.java#L57-L93","documentation":"Thrown by RedisHostAndPort.getPort() when the value holds no port. RedisHostAndPort parses strings like \"host:6379\"; if the input had no \":port\" part, hasPort() is false and any getPort() call throws this IllegalStateException. It typically fires inside RedisConnectionConfig while assembling standalone/sentinel/cluster connections.","triggerScenarios":"Building a config from a host string without a port, e.g. RedisConnectionConfig.Builder.withHost(\"redis.prod\") combined with logic that later calls getPort() on a RedisHostAndPort parsed from \"redis.prod\"; or a sentinel/cluster node list entry missing \":port\" (\"redis-node1\" instead of \"redis-node1:26379\").","commonSituations":"Operators assume a default port and omit it in config; host property contains only the hostname while the code path requires an explicit RedisHostAndPort with port; environment difference where staging configs include ports but production does not.","solutions":["Include the port in the host/node strings: \"redis.prod:6379\", sentinel entries like \"sentinel-1:26379\".","If the property may lack a port, normalize it before use: host.contains(\":\") ? host : host + \":6379\" (choose the correct default: 6379 standalone, 26379 sentinel, per your topology).","Call hasPort() before getPort() when you handle parsed RedisHostAndPort values yourself."],"exampleFix":"// before\nRedisHostAndPort hp = RedisHostAndPort.from(\"redis.prod\");\nint port = hp.getPort(); // throws \"No port present.\"\n\n// after\nRedisHostAndPort hp = RedisHostAndPort.from(\"redis.prod:6379\");\nint port = hp.getPort();","handlingStrategy":"validation","validationCode":"String normalized = host.contains(\":\") ? host : host + \":6379\"; // 26379 for sentinels\nRedisHostAndPort hp = RedisHostAndPort.from(normalized);\nint port = hp.getPort(); // safe\n\n// or check first:\nif (!hp.hasPort()) { throw new IllegalStateException(\"redis host missing port: \" + host); }","typeGuard":null,"tryCatchPattern":"try {\n    int port = hp.getPort();\n} catch (IllegalStateException e) {\n    throw new IllegalStateException(\"Redis address '\" + rawHost + \"' must include a port\", e);\n}","preventionTips":["Always configure Redis addresses as host:port strings.","Use hasPort() before getPort() when handling parsed values."],"tags":["sentinel","redis","host-and-port","config-parsing","java"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}