{"record":{"id":"7f9d9c59f7a4ac9a","repo":"grpc/grpc-java","slug":"getchannel-not-supported","errorCode":null,"errorMessage":"getChannel() not supported","messagePattern":"getChannel\\(\\) not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"android/src/main/java/io/grpc/android/UdsSocket.java","lineNumber":93,"sourceCode":"      shutdownOutput();\n    }\n    localSocket.close();\n    closed = true;\n  }\n\n  @Override\n  public void connect(SocketAddress endpoint) throws IOException {\n    localSocket.connect(localSocketAddress);\n  }\n\n  @Override\n  public void connect(SocketAddress endpoint, int timeout) throws IOException {\n    localSocket.connect(localSocketAddress, timeout);\n  }\n\n  @Override\n  public SocketChannel getChannel() {\n    throw new UnsupportedOperationException(\"getChannel() not supported\");\n  }\n\n  @Override\n  public InetAddress getInetAddress() {\n    throw new UnsupportedOperationException(\"getInetAddress() not supported\");\n  }\n\n  @Override\n  public InputStream getInputStream() throws IOException {\n    return new FilterInputStream(localSocket.getInputStream()) {\n      @Override\n      public void close() throws IOException {\n        UdsSocket.this.close();\n      }\n    };\n  }\n\n  @Override","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/android/src/main/java/io/grpc/android/UdsSocket.java#L75-L111","documentation":"UdsSocket wraps an Android LocalSocket to emulate a java.net.Socket over a Unix Domain Socket. Many java.net.Socket methods have no meaning for LocalSockets; getChannel() (which would return the associated SocketChannel) is one of them and is deliberately implemented to throw UnsupportedOperationException. The UDS transport never uses NIO channels, so there is nothing meaningful to return.","triggerScenarios":"Any code path that calls getChannel() on the Socket instance created by UdsSocketFactory — e.g. library or framework code (connection pools, socket inspectors, NIO helpers) that opportunistically checks for a SocketChannel.","commonSituations":"Instrumentation or debugging code inspecting the socket; third-party libraries assuming all java.net.Socket subclasses support NIO channels; moving gRPC-over-UDS code into a context that also uses java.nio.","solutions":["Do not call getChannel() on sockets obtained from the gRPC UDS transport; operate on the stream APIs instead.","Wrap socket access in a capability check: only use getChannel() when socket.getClass() != UdsSocket (or instanceof check fails for the wrapper).","If NIO channel semantics are required, use a TCP channel instead of UdsChannelBuilder."],"exampleFix":"// before\nSocketChannel ch = socket.getChannel();\n// after\nif (socket.getClass().getSimpleName().equals(\"UdsSocket\")) {\n  throw new IllegalStateException(\"UDS sockets have no channel\");\n}\nSocketChannel ch = socket.getChannel();","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isUdsSocket(Socket s) {\n  return s.getClass().getName().equals(\"io.grpc.android.UdsSocket\");\n}","tryCatchPattern":"try {\n  SocketChannel ch = socket.getChannel();\n  useChannel(ch);\n} catch (UnsupportedOperationException e) {\n  // UDS socket: no NIO channel; use stream-based IO\n}","preventionTips":["Treat sockets from the gRPC UDS transport as option-poor: only read/write streams, never NIO channels or TCP options.","Centralize socket inspection behind a helper that checks for UdsSocket first.","Never pass UDS sockets to libraries that require SocketChannel."],"tags":["grpc","android","unix-domain-socket","socket","unsupported"],"backgroundTag":"unsupported-operation","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}