{"record":{"id":"3563b49cdf143c21","repo":"grpc/grpc-java","slug":"unknown-negotiation-type-negotiationtype","errorCode":null,"errorMessage":"Unknown negotiation type: ${negotiationType}","messagePattern":"Unknown negotiation type: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java","lineNumber":614,"sourceCode":"\n  @VisibleForTesting\n  @Nullable\n  SSLSocketFactory createSslSocketFactory() {\n    switch (negotiationType) {\n      case TLS:\n        try {\n          if (sslSocketFactory == null) {\n            SSLContext sslContext = SSLContext.getInstance(\"Default\", Platform.get().getProvider());\n            sslSocketFactory = sslContext.getSocketFactory();\n          }\n          return sslSocketFactory;\n        } catch (GeneralSecurityException gse) {\n          throw new RuntimeException(\"TLS Provider failure\", gse);\n        }\n      case PLAINTEXT:\n        return null;\n      default:\n        throw new RuntimeException(\"Unknown negotiation type: \" + negotiationType);\n    }\n  }\n\n\n\n  private static final EnumSet<TlsChannelCredentials.Feature> understoodTlsFeatures =\n      EnumSet.of(\n          TlsChannelCredentials.Feature.MTLS, TlsChannelCredentials.Feature.CUSTOM_MANAGERS);\n\n  static SslSocketFactoryResult sslSocketFactoryFrom(ChannelCredentials creds) {\n    if (creds instanceof TlsChannelCredentials) {\n      TlsChannelCredentials tlsCreds = (TlsChannelCredentials) creds;\n      Set<TlsChannelCredentials.Feature> incomprehensible =\n          tlsCreds.incomprehensible(understoodTlsFeatures);\n      if (!incomprehensible.isEmpty()) {\n        return SslSocketFactoryResult.error(\n            \"TLS features not understood: \" + incomprehensible);\n      }","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java#L596-L632","documentation":"Thrown when the channel builder's negotiationType is neither TLS nor PLAINTEXT. Since NegotiationType is an enum, this usually only occurs through reflection, deserialization of a corrupted enum, or future enum values not handled by this switch.","triggerScenarios":"Invoking builder.negotiationType() with an unhandled NegotiationType value (e.g. via reflection, code generation, or after a library upgrade where a new enum constant exists), then calling buildTransportFactory.","commonSituations":"Binary-incompatible upgrades between grpc versions, reflection-based configuration, ProGuard/R8 enum obfuscation bugs, hand-rolled channel construction.","solutions":["Only pass NegotiationType.TLS or NegotiationType.PLAINTEXT to negotiationType()","Rebuild against a consistent grpc-okhttp version to fix enum binary-compatibility issues","Check ProGuard/R8 rules keep enum values intact","If a new constant was added upstream, upgrade grpc-okhttp where the switch handles it"],"exampleFix":"// before\nbuilder.negotiationType(someUnrecognizedType);\n// after\nif (negotiationType == NegotiationType.TLS || negotiationType == NegotiationType.PLAINTEXT) {\n  builder.negotiationType(negotiationType);\n} else {\n  builder.usePlaintext();\n}","handlingStrategy":"validation","validationCode":"Set<NegotiationType> valid = EnumSet.of(NegotiationType.TLS, NegotiationType.PLAINTEXT); if (!valid.contains(type)) throw new IllegalArgumentException(\"bad negotiation type\");","typeGuard":"boolean isKnownNegotiationType(NegotiationType t) { return t == NegotiationType.TLS || t == NegotiationType.PLAINTEXT; }","tryCatchPattern":"try { buildTransportFactory(); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Unknown negotiation type\")) { fallbackToPlaintextOrTls(); } else { throw e; } }","preventionTips":["Only use NegotiationType enum constants from your compiled grpc version","Keep grpc-okhttp versions consistent across modules","Add keep rules for grpc enums in ProGuard/R8"],"tags":["grpc","okhttp","enum","configuration"],"backgroundTag":"invalid-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"}