{"record":{"id":"61f49495e56e63cd","repo":"grpc/grpc-java","slug":"result-error-61f494","errorCode":null,"errorMessage":"${result.error}","messagePattern":"\\$\\{result\\.error\\}","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"netty/src/main/java/io/grpc/netty/InternalNettyServerCredentials.java","lineNumber":56,"sourceCode":"   * Creates a {@link ServerCredentials} that will use the provided {@code negotiator}. Use of\n   * {@link #create(io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator)} is preferred over\n   * this method when possible.\n   */\n  public static ServerCredentials create(InternalProtocolNegotiator.ServerFactory negotiator) {\n    return NettyServerCredentials.create(negotiator);\n  }\n\n  /**\n   * Converts a {@link ServerCredentials} to a negotiator, in similar fashion as for a new server.\n   *\n   * @throws IllegalArgumentException if unable to convert\n   */\n  public static InternalProtocolNegotiator.ServerFactory toNegotiator(\n      ServerCredentials serverCredentials) {\n    final ProtocolNegotiators.FromServerCredentialsResult result =\n        ProtocolNegotiators.from(serverCredentials);\n    if (result.error != null) {\n      throw new IllegalArgumentException(result.error);\n    }\n    final class ServerFactory implements InternalProtocolNegotiator.ServerFactory {\n      @Override\n      public InternalProtocolNegotiator.ProtocolNegotiator newNegotiator(\n          ObjectPool<? extends Executor> offloadExecutorPool) {\n        return new InternalProtocolNegotiator.ProtocolNegotiatorAdapter(\n            result.negotiator.newNegotiator(offloadExecutorPool));\n      }\n    }\n\n    return new ServerFactory();\n  }\n}\n","sourceCodeStart":38,"sourceCodeEnd":70,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/netty/src/main/java/io/grpc/netty/InternalNettyServerCredentials.java#L38-L70","documentation":"InternalNettyServerCredentials.toNegotiator() converts ServerCredentials via ProtocolNegotiators.from(); unsupported credential types yield a result.error string which is thrown as IllegalArgumentException. The Netty transport only understands credential types it knows how to negotiate.","triggerScenarios":"Passing a ServerCredentials implementation unknown to ProtocolNegotiators.from() into InternalNettyServerCredentials.toNegotiator().","commonSituations":"Using server credentials built by another transport module; custom ServerCredentials subclasses; internal plumbing errors when wiring custom protocol negotiators.","solutions":["Build credentials with TlsServerCredentials.newBuilder() or InsecureServerCredentials","Verify the credentials type is from grpc-netty-compatible APIs","Use NettyServerBuilder directly, which performs the same conversion with clearer paths"],"exampleFix":"// before\nInternalNettyServerCredentials.toNegotiator(customServerCreds);\n// after\nInternalNettyServerCredentials.toNegotiator(TlsServerCredentials.newBuilder().keyManager(cert, key).build());","handlingStrategy":"type-guard","validationCode":"if (!(creds instanceof TlsServerCredentials) && !(creds instanceof InsecureServerCredentials)) { throw new IllegalArgumentException(\"Unsupported ServerCredentials for Netty\"); }","typeGuard":"boolean nettyCompatible(ServerCredentials c) { return c instanceof TlsServerCredentials || c instanceof InsecureServerCredentials; }","tryCatchPattern":"try { return InternalNettyServerCredentials.toNegotiator(creds); } catch (IllegalArgumentException e) { log.error(\"Unsupported server credentials: \" + e.getMessage()); throw e; }","preventionTips":["Build server credentials via TlsServerCredentials.newBuilder()","Keep credentials creation in transport-agnostic code paths","Prefer NettyServerBuilder for Netty-specific setups"],"tags":["grpc","netty","server","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"}