{"record":{"id":"5aa22a2607f9b0b0","repo":"grpc/grpc-java","slug":"this-method-is-deprecated-and-marked-for-removal","errorCode":null,"errorMessage":"This method is deprecated and marked for removal. Use the getPeerCertificates() method instead.","messagePattern":"This method is deprecated and marked for removal\\. Use the getPeerCertificates\\(\\) method instead\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/grpc/internal/NoopSslSession.java","lineNumber":42,"sourceCode":"\n/** A no-op ssl session, to facilitate overriding only the required methods in specific\n * implementations.\n */\npublic class NoopSslSession implements SSLSession {\n  @Override\n  public byte[] getId() {\n    return new byte[0];\n  }\n\n  @Override\n  public SSLSessionContext getSessionContext() {\n    return null;\n  }\n\n  @Override\n  @SuppressWarnings(\"deprecation\")\n  public javax.security.cert.X509Certificate[] getPeerCertificateChain() {\n    throw new UnsupportedOperationException(\"This method is deprecated and marked for removal. \"\n            + \"Use the getPeerCertificates() method instead.\");\n  }\n\n  @Override\n  public long getCreationTime() {\n    return 0;\n  }\n\n  @Override\n  public long getLastAccessedTime() {\n    return 0;\n  }\n\n  @Override\n  public void invalidate() {\n  }\n\n  @Override","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/core/src/main/java/io/grpc/internal/NoopSslSession.java#L24-L60","documentation":"NoopSslSession is gRPC's placeholder SSLSession for insecure/non-TLS transports. The getPeerCertificateChain() method (javax.security.cert.X509Certificate based, deprecated since Java 9) intentionally always throws UnsupportedOperationException to steer callers to getPeerCertificates().","triggerScenarios":"Calling getPeerCertificateChain() on an SSLSession obtained from a gRPC transport's attributes (GRPC_TRANSPORT_ATTR_SSL_SESSION) when that session is a NoopSslSession, e.g. on plaintext channels.","commonSituations":"Code inspecting peer certs without checking whether TLS is actually enabled; old code using deprecated javax.security.cert APIs (also flagged for removal by Jakarta/Java 11+).","solutions":["Call getPeerCertificates() (SSLSession API) instead of getPeerCertificates() deprecated chain counterpart","Check whether the channel is actually using TLS before reading peer certs; plaintext sessions are NoopSslSession and have no peer certificates","Handle UnsupportedOperationException defensively when reading certs from unknown transports","Cast/handle the cert array as java.security.cert.X509Certificate rather than javax.security.cert.X509Certificate"],"exampleFix":"// before\njavax.security.cert.X509Certificate[] certs = session.getPeerCertificateChain();\n// after\njava.security.cert.X509Certificate[] certs = session.getPeerCertificates();","handlingStrategy":"try-catch","validationCode":"boolean hasTls = channel instanceof io.grpc.internal.ManagedChannelImpl /* check via transport attrs */;\nSSLSession s = call.getAttributes().get(Grpc.TRANSPORT_ATTR_SSL_SESSION);\nif (s == null || s.getClass().getSimpleName().equals(\"NoopSslSession\")) return;","typeGuard":"static boolean hasRealSslSession(SSLSession s) {\n  return s != null && !(s.getClass().getSimpleName().equals(\"NoopSslSession\"));\n}","tryCatchPattern":"try { certs = session.getPeerCertificates(); } catch (UnsupportedOperationException | SSLPeerUnverifiedException e) { certs = null; }","preventionTips":["Use getPeerCertificates(), never the deprecated getPeerCertificateChain()","Only read peer certs when TLS is actually enabled","Handle NoopSslSession/empty cert arrays as \"no TLS\""],"tags":["grpc","tls","ssl","deprecated","unsupported-operation"],"backgroundTag":"deprecated-api-usage","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"}