{"record":{"id":"df8def9b1ac1870f","repo":"apache/cassandra","slug":"missing-port-number","errorCode":null,"errorMessage":"Missing port number","messagePattern":"Missing port number","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/transport/Server.java","lineNumber":288,"sourceCode":"        public Builder withEventNotifier(EventNotifier eventNotifier)\n        {\n            this.eventNotifier = eventNotifier;\n            return this;\n        }\n\n        public Server build()\n        {\n            return new Server(this);\n        }\n\n        private InetSocketAddress getSocket()\n        {\n            if (this.socket != null)\n                return this.socket;\n            else\n            {\n                if (this.port == -1)\n                    throw new IllegalStateException(\"Missing port number\");\n                if (this.hostAddr != null)\n                    this.socket = new InetSocketAddress(this.hostAddr, this.port);\n                else\n                    throw new IllegalStateException(\"Missing host\");\n                return this.socket;\n            }\n        }\n    }\n\n    public static class ConnectionTracker implements Connection.Tracker\n    {\n        private static final ChannelMatcher PRE_V5_CHANNEL = channel -> channel.attr(Connection.attributeKey)\n                                                                               .get()\n                                                                               .getVersion()\n                                                                               .isSmallerThan(ProtocolVersion.V5);\n\n        // TODO: should we be using the GlobalEventExecutor or defining our own?\n        public final ChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/transport/Server.java#L270-L306","documentation":"Thrown by Server.getSocket() when the Builder was never given a port, so no InetSocketAddress can be constructed. The builder defers socket creation until start time and throws an IllegalStateException rather than a build-time error if neither a socket nor (port) is set. This is a programming/configuration mistake in server setup code.","triggerScenarios":"Building a Server via Server.Builder with only a host address (or nothing) — port remains the default -1 — then calling getSocket()/start(); this.socket is null, this.port == -1 triggers the throw.","commonSituations":"Embedding Cassandra's transport in tests or tools and forgetting Builder.port(...), copying builder code and deleting the port line, or setting an InetSocketAddress field that is later cleared.","solutions":["Call Server.Builder.port(int) with the desired native transport port before building","Or pass a complete InetSocketAddress via the socket(...) builder method instead","Add a unit test constructing the server the same way production code does to catch this at CI time","Log/assert builder completeness before start() in embedding code"],"exampleFix":"// before\nServer.builder().withHost(addr).build();\n// after\nServer.builder().withHost(addr).withPort(9042).build();","handlingStrategy":"validation","validationCode":"if (builderPort == -1) throw new IllegalArgumentException(\"Server.Builder requires a port; call port(...) or socket(...)\");","typeGuard":"boolean readyToBuild(Server.Builder b) { return b.getPort() != -1; }","tryCatchPattern":"try { server.start(); } catch (IllegalStateException e) { if (e.getMessage().equals(\"Missing port number\")) { fixBuilderConfig(); } else throw e; }","preventionTips":["Always set both host and port in Server.Builder","Create servers through a single factory method that validates config","Add a builder test in CI covering the embed path","Fail fast with config validation at application startup"],"tags":["configuration","builder","missing-port","native-transport"],"backgroundTag":"missing-required-argument","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}