grpc/grpc-java · info · UnsupportedOperationException
Unsupported operation getPort()
Error message
Unsupported operation getPort()
What it means
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.
Source
Thrown at android/src/main/java/io/grpc/android/UdsSocket.java:148
@Override
public boolean getOOBInline() {
throw new UnsupportedOperationException("Unsupported operation getOOBInline()");
}
@Override
public OutputStream getOutputStream() throws IOException {
return new FilterOutputStream(localSocket.getOutputStream()) {
@Override
public void close() throws IOException {
UdsSocket.this.close();
}
};
}
@Override
public int getPort() {
throw new UnsupportedOperationException("Unsupported operation getPort()");
}
@Override
public int getReceiveBufferSize() throws SocketException {
try {
return localSocket.getReceiveBufferSize();
} catch (IOException e) {
throw toSocketException(e);
}
}
@Override
public SocketAddress getRemoteSocketAddress() {
return new SocketAddress() {};
}
@Override
public boolean getReuseAddress() {View on GitHub (pinned to 64daddc1f3)
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
Example fix
// before
int port = socket.getPort();
// after
if (socket instanceof io.grpc.android.UdsSocket) {
// Unix domain socket: no port; use the socket path instead
} else {
int port = socket.getPort();
} Defensive patterns
Strategy: try-catch
Validate before calling
boolean hasPort = !(socket instanceof io.grpc.android.UdsSocket);
Type guard
static boolean supportsPort(java.net.Socket s) { return !(s instanceof io.grpc.android.UdsSocket); } Try / catch
try { port = socket.getPort(); } catch (UnsupportedOperationException e) { port = -1; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- OkHttpChannelBuilder not found on the classpath
- getChannel() not supported
- getInetAddress() not supported
- Unsupported operation getKeepAlive()
- Unsupported operation getLocalAddress()
AI-assisted analysis of grpc/grpc-java@64daddc1f3 (2026-09-08).
Data as JSON: /api/errors/f026ed3062be17ae.
Report an issue: GitHub.