{"record":{"id":"5c5056a30ea8d21b","repo":"grpc/grpc-java","slug":"unsupported-negotiationtype-negotiationtype","errorCode":null,"errorMessage":"Unsupported negotiationType: ${negotiationType}","messagePattern":"Unsupported negotiationType: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java","lineNumber":712,"sourceCode":"\n  int getDefaultPort() {\n    return protocolNegotiatorFactory.getDefaultPort();\n  }\n\n  @VisibleForTesting\n  static ProtocolNegotiator createProtocolNegotiatorByType(\n      NegotiationType negotiationType,\n      SslContext sslContext,\n      ObjectPool<? extends Executor> executorPool) {\n    switch (negotiationType) {\n      case PLAINTEXT:\n        return ProtocolNegotiators.plaintext();\n      case PLAINTEXT_UPGRADE:\n        return ProtocolNegotiators.plaintextUpgrade();\n      case TLS:\n        return ProtocolNegotiators.tls(sslContext, executorPool, Optional.absent(), null, null);\n      default:\n        throw new IllegalArgumentException(\"Unsupported negotiationType: \" + negotiationType);\n    }\n  }\n\n  @CanIgnoreReturnValue\n  NettyChannelBuilder disableCheckAuthority() {\n    this.managedChannelImplBuilder.disableCheckAuthority();\n    return this;\n  }\n\n  @CanIgnoreReturnValue\n  NettyChannelBuilder enableCheckAuthority() {\n    this.managedChannelImplBuilder.enableCheckAuthority();\n    return this;\n  }\n\n  void protocolNegotiatorFactory(ProtocolNegotiator.ClientFactory protocolNegotiatorFactory) {\n    checkState(!freezeProtocolNegotiatorFactory,\n               \"Cannot change security when using ChannelCredentials\");","sourceCodeStart":694,"sourceCodeEnd":730,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java#L694-L730","documentation":"createProtocolNegotiatorByType() switches over the configured NegotiationType (PLAINTEXT, PLAINTEXT_UPGRADE, TLS). If negotiationType holds a value outside the known enum cases, the default branch throws IllegalArgumentException(\"Unsupported negotiationType: ...\"). This guards against unknown or corrupted enum values reaching negotiator creation.","triggerScenarios":"Calling negotiationType(NegotiationType.X) with an enum constant not handled by the switch (e.g. a NegotiationType from a newer/older grpc version that this switch does not cover), or an internal call path supplying a null/foreign enum value.","commonSituations":"Version skew where code compiled against a newer grpc-core NegotiationType runs against an older grpc-netty; reflection or deserialization producing an unexpected enum value; custom subclasses of the builder overriding negotiationType handling.","solutions":["Use only NegotiationType.PLAINTEXT, PLAINTEXT_UPGRADE, or TLS when calling negotiationType().","Align grpc-netty and grpc-core/grpc-api versions (use grpc-bom) so enum constants match.","If TLS is intended, call negotiationType(NegotiationType.TLS) or use the shorthand usePlaintext()/useTransportSecurity().","Rebuild your code against the same grpc version as the runtime dependency."],"exampleFix":"// before\nbuilder.negotiationType(myNegotiationType); // may hold an unhandled value\n// after\nif (useTls) {\n  builder.negotiationType(NegotiationType.TLS);\n} else {\n  builder.usePlaintext();\n}","handlingStrategy":"validation","validationCode":"if (type != NegotiationType.PLAINTEXT && type != NegotiationType.PLAINTEXT_UPGRADE && type != NegotiationType.TLS) {\n  throw new IllegalStateException(\"NegotiationType not supported by NettyChannelBuilder: \" + type);\n}","typeGuard":"static boolean isSupportedNegotiationType(NegotiationType t) {\n  return t == NegotiationType.PLAINTEXT || t == NegotiationType.PLAINTEXT_UPGRADE || t == NegotiationType.TLS;\n}","tryCatchPattern":"try {\n  channel.build();\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Unsupported negotiationType\")) {\n    builder.usePlaintext(); // safe default\n  }\n}","preventionTips":["Pin grpc-netty, grpc-core, grpc-api to one version via grpc-bom","Prefer builder.usePlaintext()/useTransportSecurity() shorthands over raw enum assignment","Recompile against the runtime grpc version after upgrades"],"tags":["grpc","java","enum","negotiation-type"],"backgroundTag":"unsupported-enum-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"}