{"record":{"id":"f026ed3062be17ae","repo":"grpc/grpc-java","slug":"unsupported-operation-getport","errorCode":null,"errorMessage":"Unsupported operation getPort()","messagePattern":"Unsupported operation getPort\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"info","filePath":"android/src/main/java/io/grpc/android/UdsSocket.java","lineNumber":148,"sourceCode":"\n  @Override\n  public boolean getOOBInline() {\n    throw new UnsupportedOperationException(\"Unsupported operation getOOBInline()\");\n  }\n\n  @Override\n  public OutputStream getOutputStream() throws IOException {\n    return new FilterOutputStream(localSocket.getOutputStream()) {\n      @Override\n      public void close() throws IOException {\n        UdsSocket.this.close();\n      }\n    };\n  }\n\n  @Override\n  public int getPort() {\n    throw new UnsupportedOperationException(\"Unsupported operation getPort()\");\n  }\n\n  @Override\n  public int getReceiveBufferSize() throws SocketException {\n    try {\n      return localSocket.getReceiveBufferSize();\n    } catch (IOException e) {\n      throw toSocketException(e);\n    }\n  }\n\n  @Override\n  public SocketAddress getRemoteSocketAddress() {\n    return new SocketAddress() {};\n  }\n\n  @Override\n  public boolean getReuseAddress() {","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/android/src/main/java/io/grpc/android/UdsSocket.java#L130-L166","documentation":"UdsSocket wraps a LocalSocket for Unix-domain-socket gRPC transport on Android. java.net.Socket's getPort() has no meaning for a UDS (there is no TCP port), so the override unconditionally throws UnsupportedOperationException. It exists only to satisfy the Socket abstract API; callers must not invoke it.","triggerScenarios":"Any code path that calls UdsSocket.getPort() directly, or library/framework code that introspects the socket (e.g. channel factories, socket diagnostics, connection logging) and asks for the remote/local port.","commonSituations":"Developers treating the UDS channel like a TCP channel; middleware or debug tooling that logs socket endpoints; migrating code from a TCP gRPC channel to a 'uds:' target without removing port-related socket inspection.","solutions":["Stop calling getPort() on UdsSocket; a Unix domain socket has no port — derive endpoint info from the socket file path instead","Guard socket introspection code with an instanceof/UDS check before querying port-related options","If port info is genuinely needed, use a TCP (host:port) gRPC target rather than the UDS transport"],"exampleFix":"// before\nint port = socket.getPort();\n// after\nif (socket instanceof io.grpc.android.UdsSocket) {\n  // Unix domain socket: no port; use the socket path instead\n} else {\n  int port = socket.getPort();\n}","handlingStrategy":"try-catch","validationCode":"boolean hasPort = !(socket instanceof io.grpc.android.UdsSocket);","typeGuard":"static boolean supportsPort(java.net.Socket s) { return !(s instanceof io.grpc.android.UdsSocket); }","tryCatchPattern":"try { port = socket.getPort(); } catch (UnsupportedOperationException e) { port = -1; }","preventionTips":["Treat UdsSocket as a portless transport: never query port-related Socket accessors on it","Centralize socket introspection behind a helper that checks for UDS first","When switching gRPC targets from host:port to 'uds:', audit any code reading socket endpoints"],"tags":["grpc","android","unix-domain-socket","unsupported-operation"],"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"}