{"record":{"id":"8f4feb7f22f8ebb1","repo":"apache/shenyu","slug":"unsupported-socketaddress-type-socketaddress-getclass","errorCode":null,"errorMessage":"Unsupported SocketAddress type: ${socketAddress.getClass().getName()}","messagePattern":"Unsupported SocketAddress type: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"shenyu-protocol/shenyu-protocol-tcp/src/main/java/org/apache/shenyu/protocol/tcp/TcpBootstrapServer.java","lineNumber":121,"sourceCode":"        client.subscribe(\n            clientConn -> bridge.bridge(serverConn, clientConn),\n            error -> {\n                LOG.error(\"Failed to establish client connection for {}\", serverConn, error);\n                eventBus.unregister(connectionObserver);\n                serverConn.dispose();\n            }\n        );\n    }\n\n    private String getIp(final SocketAddress socketAddress) {\n        if (Objects.isNull(socketAddress)) {\n            throw new NullPointerException(\"remoteAddress is null\");\n        }\n        if (socketAddress instanceof InetSocketAddress) {\n            return ((InetSocketAddress) socketAddress).getHostString();\n        }\n        LOG.error(\"Unsupported SocketAddress type: {}\", socketAddress.getClass().getName());\n        throw new IllegalArgumentException(\"Unsupported SocketAddress type: \" + socketAddress.getClass().getName());\n    }\n\n    /**\n     * doOnUpdate.\n     *\n     * @param removeList removeList\n     */\n    @Override\n    public void removeCommonUpstream(final List<DiscoveryUpstreamData> removeList) {\n        eventBus.post(removeList);\n    }\n\n\n    /**\n     * shutdown.\n     */\n    @Override\n    public synchronized void shutdown() {","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-protocol/shenyu-protocol-tcp/src/main/java/org/apache/shenyu/protocol/tcp/TcpBootstrapServer.java#L103-L139","documentation":"TcpBootstrapServer.getIp only supports java.net.InetSocketAddress for extracting the peer host; any other SocketAddress implementation is logged and rejected with IllegalArgumentException('Unsupported SocketAddress type: <class>'). The gateway's TCP protocol handling expects an IP-socket peer and cannot derive an address from other address families (e.g. Unix domain sockets, custom address types).","triggerScenarios":"getIp (invoked from the TCP client handler) receives a remoteAddress that is not an InetSocketAddress — e.g. DomainSocketAddress from Unix-domain sockets or a third-party/custom SocketAddress subclass attached to the connection.","commonSituations":"Running the TCP gateway over Unix domain sockets or exotic transports; frameworks or tests injecting mock SocketAddress implementations; custom Netty channel configurations that report non-inet addresses.","solutions":["Connect clients to the TCP gateway over TCP/IP so remote addresses are InetSocketAddress instances.","If Unix domain sockets are required, extend getIp (or the surrounding handler) to handle DomainSocketAddress explicitly and extract the path instead of the host.","Audit any custom Netty channel/transport configuration that could supply non-inet remote addresses.","In tests, provide real InetSocketAddress mocks rather than generic SocketAddress fakes."],"exampleFix":"// before\nif (socketAddress instanceof InetSocketAddress) { ... }\n// after\nif (socketAddress instanceof InetSocketAddress isa) { return isa.getHostString(); }\nif (socketAddress instanceof DomainSocketAddress dom) { return dom.path(); }","handlingStrategy":"type-guard","validationCode":"SocketAddress addr = connection.remoteAddress();\nif (!(addr instanceof InetSocketAddress)) { /* reject non-IP transports */ }","typeGuard":"static boolean isIpSocket(SocketAddress addr) {\n    return addr instanceof InetSocketAddress;\n}\n// usage\nif (!isIpSocket(socketAddress)) { /* unsupported transport: reject */ }","tryCatchPattern":"try {\n    String ip = getIp(socketAddress);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unsupported SocketAddress type\")) { /* handle non-inet transport or reject */ }\n    throw e;\n}","preventionTips":["Expose the TCP gateway over TCP/IP, not Unix domain sockets or custom transports.","Reject non-InetSocketAddress connections at the accept/handshake stage.","In tests, use real InetSocketAddress values."],"tags":["tcp","network","type-mismatch","socket-address"],"backgroundTag":"type-mismatch","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}