{"record":{"id":"d49fb9360d5576ac","repo":"grpc/grpc-java","slug":"anonymousinprocesssocketaddress-is-not-serializabl","errorCode":null,"errorMessage":"AnonymousInProcessSocketAddress is not serializable","messagePattern":"AnonymousInProcessSocketAddress is not serializable","errorType":"exception","errorClass":"NotSerializableException","httpStatus":null,"severity":"error","filePath":"inprocess/src/main/java/io/grpc/inprocess/AnonymousInProcessSocketAddress.java","lineNumber":43,"sourceCode":"import java.io.ObjectOutputStream;\nimport java.net.SocketAddress;\nimport javax.annotation.Nullable;\n\n/**\n * Custom SocketAddress class for {@link InProcessTransport}, for \n * a server which can only be referenced via this address instance.\n */\n@ExperimentalApi(\"https://github.com/grpc/grpc-java/issues/8626\")\npublic final class AnonymousInProcessSocketAddress extends SocketAddress {\n  private static final long serialVersionUID = -8567592561863414695L;\n\n  @Nullable\n  @GuardedBy(\"this\")\n  @SuppressWarnings(\"serial\")\n  private InProcessServer server;\n\n  private void writeObject(ObjectOutputStream out) throws IOException {\n    throw new NotSerializableException(\"AnonymousInProcessSocketAddress is not serializable\");\n  }\n\n  /** Creates a new AnonymousInProcessSocketAddress. */\n  public AnonymousInProcessSocketAddress() { }\n\n  @Nullable\n  synchronized InProcessServer getServer() {\n    return server;\n  }\n\n  synchronized void setServer(InProcessServer server) throws IOException {\n    if (this.server != null) {\n      throw new IOException(\"Server instance already registered\");\n    }\n    this.server = server;\n  }\n\n  synchronized void clearServer(InProcessServer server) {","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/inprocess/src/main/java/io/grpc/inprocess/AnonymousInProcessSocketAddress.java#L25-L61","documentation":"AnonymousInProcessSocketAddress is deliberately non-serializable because it refers to a live in-process server instance that cannot be meaningfully serialized; its writeObject hook throws NotSerializableException to enforce this. It only makes sense within the same JVM.","triggerScenarios":"Attempting to serialize an AnonymousInProcessSocketAddress, e.g. passing it through Java serialization, storing it in a serializable object graph, or sending it over a remoting/session mechanism.","commonSituations":"Putting the server's anonymous listen address into an HttpSession, caching it to disk, or embedding it in a message sent over the wire.","solutions":["Do not serialize anonymous socket addresses; keep them in-JVM only.","Use a named InProcessSocketAddress(name) (which is serializable by name) if the address must cross boundaries.","Exclude the field from serialization (transient) or store the server's registered name instead."],"exampleFix":"// before\nclass Context implements Serializable { AnonymousInProcessSocketAddress addr; }\n// after\nclass Context implements Serializable { transient AnonymousInProcessSocketAddress addr; String serverName; }","handlingStrategy":"type-guard","validationCode":"if (addr instanceof AnonymousInProcessSocketAddress) throw new IllegalArgumentException(\"anonymous address cannot be serialized; store the server name instead\");","typeGuard":"boolean isSerializableAddress(SocketAddress a) { return a instanceof InProcessSocketAddress; }","tryCatchPattern":null,"preventionTips":["Keep anonymous addresses in-JVM only","Mark fields holding them as transient","Persist the server name, not the address object"],"tags":["grpc","inprocess","serialization"],"backgroundTag":"unsupported-operation","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}