{"record":{"id":"f97033a025301596","repo":"grpc/grpc-java","slug":"result-error","errorCode":null,"errorMessage":"${result.error}","messagePattern":"\\$\\{result\\.error\\}","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"netty/src/main/java/io/grpc/netty/InternalNettyChannelCredentials.java","lineNumber":45,"sourceCode":"public final class InternalNettyChannelCredentials {\n  private InternalNettyChannelCredentials() {}\n\n  /** Creates a {@link ChannelCredentials} that will use the provided {@code negotiator}. */\n  public static ChannelCredentials create(InternalProtocolNegotiator.ClientFactory negotiator) {\n    return NettyChannelCredentials.create(negotiator);\n  }\n\n  /**\n   * Converts a {@link ChannelCredentials} to a negotiator, in similar fashion as for a new channel.\n   *\n   * @throws IllegalArgumentException if unable to convert\n   */\n  public static InternalProtocolNegotiator.ClientFactory toNegotiator(\n      ChannelCredentials channelCredentials) {\n    final ProtocolNegotiators.FromChannelCredentialsResult result =\n        ProtocolNegotiators.from(channelCredentials);\n    if (result.error != null) {\n      throw new IllegalArgumentException(result.error);\n    }\n    final class ClientFactory implements InternalProtocolNegotiator.ClientFactory {\n\n      @Override\n      public InternalProtocolNegotiator.ProtocolNegotiator newNegotiator() {\n        return new InternalProtocolNegotiator.ProtocolNegotiatorAdapter(\n            result.negotiator.newNegotiator());\n      }\n\n      @Override\n      public int getDefaultPort() {\n        return result.negotiator.getDefaultPort();\n      }\n    }\n\n    return new ClientFactory();\n  }\n}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/netty/src/main/java/io/grpc/netty/InternalNettyChannelCredentials.java#L27-L63","documentation":"InternalNettyChannelCredentials.toNegotiator() converts arbitrary ChannelCredentials via ProtocolNegotiators.from(), which returns a result object with an error string instead of throwing. If the credentials type is unsupported, the error string is wrapped in an IllegalArgumentException.","triggerScenarios":"Passing a ChannelCredentials that ProtocolNegotiators.from() cannot handle (e.g. a custom or composite credentials type unknown to the Netty transport) into InternalNettyChannelCredentials.toNegotiator().","commonSituations":"Mixing credentials from a different transport (e.g. in-process or okhttp credentials) into a Netty channel; custom ChannelCredentials implementations; internal API misuse when building custom transports.","solutions":["Use NettyChannelCredentials TLS credentials or InsecureChannelCredentials with the Netty transport","Check the credentials were produced by NettyChannelCredentials/Plaintext APIs, not another transport's builder","Wrap in the transport-appropriate credentials type before calling toNegotiator"],"exampleFix":"// before\nInternalNettyChannelCredentials.toNegotiator(otherTransportCreds);\n// after\nInternalNettyChannelCredentials.toNegotiator(TlsChannelCredentials.newBuilder().build());","handlingStrategy":"type-guard","validationCode":"if (!(creds instanceof TlsChannelCredentials) && !(creds instanceof InsecureChannelCredentials)) { throw new IllegalArgumentException(\"Unsupported ChannelCredentials for Netty\"); }","typeGuard":"boolean nettyCompatible(ChannelCredentials c) { return c instanceof TlsChannelCredentials || c instanceof InsecureChannelCredentials; }","tryCatchPattern":"try { return InternalNettyChannelCredentials.toNegotiator(creds); } catch (IllegalArgumentException e) { log.error(\"Unsupported credentials: \" + e.getMessage()); throw e; }","preventionTips":["Create credentials with TlsChannelCredentials/InsecureChannelCredentials","Do not mix credentials across transport modules","Avoid internal APIs (InternalNetty*) unless building custom transports"],"tags":["grpc","netty","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"}