{"record":{"id":"47500168c7f67036","repo":"grpc/grpc-java","slug":"result-error-475001","errorCode":null,"errorMessage":"${result.error}","messagePattern":"\\$\\{result\\.error\\}","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java","lineNumber":154,"sourceCode":"   * noticing changes to DNS. If an unresolved InetSocketAddress is passed in, then it will remain\n   * unresolved.\n   */\n  public static NettyChannelBuilder forAddress(SocketAddress serverAddress) {\n    return new NettyChannelBuilder(serverAddress);\n  }\n\n  /**\n   * Creates a new builder with the given server address. This factory method is primarily intended\n   * for using Netty Channel types other than SocketChannel.\n   * {@link #forAddress(String, int, ChannelCredentials)} should generally be preferred over this\n   * method, since that API permits delaying DNS lookups and noticing changes to DNS. If an\n   * unresolved InetSocketAddress is passed in, then it will remain unresolved.\n   */\n  public static NettyChannelBuilder forAddress(SocketAddress serverAddress,\n      ChannelCredentials creds) {\n    FromChannelCredentialsResult result = ProtocolNegotiators.from(creds);\n    if (result.error != null) {\n      throw new IllegalArgumentException(result.error);\n    }\n    return new NettyChannelBuilder(serverAddress, creds, result.callCredentials, result.negotiator);\n  }\n\n  /**\n   * Creates a new builder with the given host and port.\n   */\n  public static NettyChannelBuilder forAddress(String host, int port) {\n    return forTarget(GrpcUtil.authorityFromHostAndPort(host, port));\n  }\n\n  /**\n   * Creates a new builder with the given host and port.\n   */\n  public static NettyChannelBuilder forAddress(String host, int port, ChannelCredentials creds) {\n    return forTarget(GrpcUtil.authorityFromHostAndPort(host, port), creds);\n  }\n","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java#L136-L172","documentation":"NettyChannelBuilder.forAddress(SocketAddress, ChannelCredentials) validates the credentials up front via ProtocolNegotiators.from(); if the credentials type cannot produce a Netty protocol negotiator, the resulting error string is thrown as IllegalArgumentException before any channel is built.","triggerScenarios":"Calling NettyChannelBuilder.forAddress(addr, creds) with credentials the Netty transport does not support (e.g. credentials created for a different transport implementation).","commonSituations":"Passing in-process or alternative-transport ChannelCredentials to a Netty builder; custom ChannelCredentials; accidentally swapping channel/target pairs in forAddress overloads.","solutions":["Use TlsChannelCredentials or InsecureChannelCredentials, which Netty supports","Obtain credentials from NettyChannelCredentials.builder() for Netty-specific features","Check that the creds argument was not accidentally swapped with the target/address"],"exampleFix":"// before\nNettyChannelBuilder.forAddress(addr, inProcessCreds);\n// after\nNettyChannelBuilder.forAddress(addr, TlsChannelCredentials.newBuilder().trustManager(caCerts).build());","handlingStrategy":"validation","validationCode":"if (!(creds instanceof TlsChannelCredentials) && !(creds instanceof InsecureChannelCredentials)) { throw new IllegalArgumentException(\"NettyChannelBuilder requires TLS or insecure credentials\"); }","typeGuard":"boolean usableByNetty(ChannelCredentials c) { return c instanceof TlsChannelCredentials || c instanceof InsecureChannelCredentials; }","tryCatchPattern":"try { builder = NettyChannelBuilder.forAddress(addr, creds); } catch (IllegalArgumentException e) { log.error(\"Incompatible credentials for Netty: \" + e.getMessage()); throw e; }","preventionTips":["Use NettyChannelCredentials/TlsChannelCredentials with NettyChannelBuilder","Double-check forAddress argument order (address first, creds second)","Centralize channel credentials creation to prevent transport mismatches"],"tags":["grpc","netty","channel","credentials","invalid-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"}