{"record":{"id":"9aea35d32c7840c7","repo":"grpc/grpc-java","slug":"result-error-9aea35","errorCode":null,"errorMessage":"${result.error}","messagePattern":"\\$\\{result\\.error\\}","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"netty/src/main/java/io/grpc/netty/NettyServerBuilder.java","lineNumber":167,"sourceCode":"   * Creates a server builder configured with the given {@link SocketAddress}.\n   *\n   * @param address the socket address on which the server is to be bound.\n   * @return the server builder\n   */\n  public static NettyServerBuilder forAddress(SocketAddress address) {\n    return new NettyServerBuilder(address);\n  }\n\n  /**\n   * Creates a server builder configured with the given {@link SocketAddress}.\n   *\n   * @param address the socket address on which the server is to be bound.\n   * @return the server builder\n   */\n  public static NettyServerBuilder forAddress(SocketAddress address, ServerCredentials creds) {\n    ProtocolNegotiators.FromServerCredentialsResult result = ProtocolNegotiators.from(creds);\n    if (result.error != null) {\n      throw new IllegalArgumentException(result.error);\n    }\n    return new NettyServerBuilder(address, result.negotiator);\n  }\n\n  private final class NettyClientTransportServersBuilder implements ClientTransportServersBuilder {\n    @Override\n    public InternalServer buildClientTransportServers(\n        List<? extends ServerStreamTracer.Factory> streamTracerFactories,\n        MetricRecorder metricRecorder) {\n      return buildTransportServers(streamTracerFactories, metricRecorder);\n    }\n  }\n\n  private NettyServerBuilder(SocketAddress address) {\n    serverImplBuilder = new ServerImplBuilder(new NettyClientTransportServersBuilder());\n    this.listenAddresses.add(address);\n    this.protocolNegotiatorFactory = ProtocolNegotiators.serverPlaintextFactory();\n    this.freezeProtocolNegotiatorFactory = false;","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java#L149-L185","documentation":"NettyServerBuilder.forAddress() validates the provided ServerCredentials through ProtocolNegotiators.from(creds). If the credentials are null or of an unsupported type, the resulting result.error string is thrown as an IllegalArgumentException. This fails fast before any server resources are created.","triggerScenarios":"Calling NettyServerBuilder.forAddress(addr, creds) with null ServerCredentials, an unrecognized ServerCredentials subclass, or TlsServerCredentials whose conversion produces an error — the error string from ProtocolNegotiators.from() is thrown verbatim.","commonSituations":"Passing credentials intended for the client side (ChannelCredentials) instead of ServerCredentials; custom ServerCredentials implementations the Netty transport cannot handle; version/classpath mismatch between grpc-api and grpc-netty.","solutions":["Use supported ServerCredentials: TlsServerCredentials.create() or InsecureServerCredentials.create().","Read the thrown message — it is produced by ProtocolNegotiators.from() and names the offending credentials.","Do not pass ChannelCredentials to a server builder; build server-side credentials instead.","Align grpc-netty and grpc-api versions (grpc-bom) to avoid class skew."],"exampleFix":"// before\nServer server = NettyServerBuilder.forAddress(port, channelCreds) // wrong credentials type\n    .build();\n// after\nServer server = NettyServerBuilder.forAddress(new InetSocketAddress(port),\n    TlsServerCredentials.newBuilder().build()).build();","handlingStrategy":"validation","validationCode":"if (creds == null || creds instanceof io.grpc.InsecureServerCredentials || creds instanceof io.grpc.TlsServerCredentials) {\n  // supported by grpc-netty server builder\n}","typeGuard":"static boolean isNettySupportedServerCredentials(ServerCredentials c) {\n  return c instanceof TlsServerCredentials || c instanceof InsecureServerCredentials;\n}","tryCatchPattern":"try {\n  Server s = NettyServerBuilder.forAddress(addr, creds).build();\n} catch (IllegalArgumentException e) {\n  // message comes from ProtocolNegotiators.from(); swap to TlsServerCredentials/InsecureServerCredentials\n}","preventionTips":["Never pass client ChannelCredentials to server builders","Use TlsServerCredentials/InsecureServerCredentials only","Keep grpc-api and grpc-netty versions aligned"],"tags":["grpc","java","server-credentials","illegal-argument"],"backgroundTag":"invalid-argument-value","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"}