grpc/grpc-java · info · UnsupportedOperationException

Unsupported operation getReuseAddress()

Error message

Unsupported operation getReuseAddress()

What it means

getReuseAddress() reports the SO_REUSEADDR socket option, which is a TCP/IP concept and not supported by the underlying Android LocalSocket used by UdsSocket. The override throws UnsupportedOperationException unconditionally rather than returning a misleading value.

Solutions

  1. Do not query SO_REUSEADDR on UdsSocket; it does not apply to Unix domain sockets
  2. Make option-reading code skip unsupported options for UDS sockets (catch UnsupportedOperationException or check socket type first)
  3. Use an AndroidChannelBuilder/plain LocalSocket API surface instead of java.net.Socket option accessors

Example fix

// before
boolean reuse = socket.getReuseAddress();
// after
if (socket instanceof io.grpc.android.UdsSocket) {
  // SO_REUSEADDR not applicable to UDS
} else {
  boolean reuse = socket.getReuseAddress();
}
Defensive patterns

Strategy: try-catch

Validate before calling

boolean canReadReuseAddr = !(socket instanceof io.grpc.android.UdsSocket);

Type guard

static boolean supportsSocketOptions(java.net.Socket s) { return !(s instanceof io.grpc.android.UdsSocket); }

Try / catch

try { reuse = socket.getReuseAddress(); } catch (UnsupportedOperationException e) { reuse = false; }

Prevention

When it happens

Trigger: Calling UdsSocket.getReuseAddress() directly, or framework code that reads all standard socket options (e.g. generic socket configuration/inspection utilities) on this socket.

Common situations: Applying a shared SocketOption configurator written for TCP sockets to the UDS transport; copying connection-setup code from a TCP gRPC channel into a UDS one.

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


AI-assisted analysis of grpc/grpc-java@64daddc1f3 (2026-09-08). Data as JSON: /api/errors/f6a9a7052087131b. Report an issue: GitHub.

Appendix: source

Thrown at android/src/main/java/io/grpc/android/UdsSocket.java:167

  }

  @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() {
    throw new UnsupportedOperationException("Unsupported operation getReuseAddress()");
  }

  @Override
  public int getSendBufferSize() throws SocketException {
    try {
      return localSocket.getSendBufferSize();
    } catch (IOException e) {
      throw toSocketException(e);
    }
  }

  @Override
  public int getSoLinger() {
    return -1; // unsupported
  }

  @Override
  public int getSoTimeout() throws SocketException {

View on GitHub (pinned to 64daddc1f3)