{"record":{"id":"5d06710171f0333a","repo":"grpc/grpc-java","slug":"unsupported-operation-getlocaladdress","errorCode":null,"errorMessage":"Unsupported operation getLocalAddress()","messagePattern":"Unsupported operation getLocalAddress\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"android/src/main/java/io/grpc/android/UdsSocket.java","lineNumber":118,"sourceCode":"\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\n  public boolean getKeepAlive() {\n    throw new UnsupportedOperationException(\"Unsupported operation getKeepAlive()\");\n  }\n\n  @Override\n  public InetAddress getLocalAddress() {\n    throw new UnsupportedOperationException(\"Unsupported operation getLocalAddress()\");\n  }\n\n  @Override\n  public int getLocalPort() {\n    throw new UnsupportedOperationException(\"Unsupported operation getLocalPort()\");\n  }\n\n  @Override\n  public SocketAddress getLocalSocketAddress() {\n    return new SocketAddress() {};\n  }\n\n  @Override\n  public boolean getOOBInline() {\n    throw new UnsupportedOperationException(\"Unsupported operation getOOBInline()\");\n  }\n\n  @Override","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/android/src/main/java/io/grpc/android/UdsSocket.java#L100-L136","documentation":"UdsSocket emulates java.net.Socket over an Android LocalSocket. A Unix Domain Socket has no IP local address, so getLocalAddress() intentionally throws UnsupportedOperationException. UdsSocket instead exposes getLocalSocketAddress() returning an opaque, typeless SocketAddress placeholder.","triggerScenarios":"Calling getLocalAddress() on the UdsSocket created by UdsSocketFactory — e.g. bind/audit logging, connection-tracking code, or libraries that record both local and remote InetAddress for every socket.","commonSituations":"Network telemetry frameworks assuming IP sockets; security/audit code capturing local bind addresses; tests verifying socket state.","solutions":["Skip IP-local-address capture for UDS sockets; identify the endpoint by the UDS path instead.","Guard with a UdsSocket check or catch UnsupportedOperationException in shared socket-inspection code.","Use getLocalSocketAddress()'s placeholder only for existence checks, never for address data."],"exampleFix":"// before\nInetAddress local = socket.getLocalAddress();\n// after\nInetAddress local = socket.getClass().getSimpleName().equals(\"UdsSocket\")\n    ? null\n    : socket.getLocalAddress();","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  InetAddress local = socket.getLocalAddress();\n} catch (UnsupportedOperationException e) {\n  // UDS: no IP local address; use the configured UDS path\n}","preventionTips":["Never record local/remote IP addresses unconditionally; make them nullable for UDS.","Use the UDS path as the connection identifier in logs and audits.","Wrap shared socket-inspection code with a UdsSocket check."],"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"}