Class OpenSslEngineMap


  • final class OpenSslEngineMap
    extends java.lang.Object
    Maps a native SSL* pointer to its ReferenceCountedOpenSslEngine so native OpenSSL callbacks (certificate verification, private-key operations, certificate (de)compression) can recover the engine from the raw pointer they are handed.

    Engines are held weakly so a leaked engine is not pinned by the long-lived parent ReferenceCountedOpenSslContext (a live engine is always strongly reachable via its SslHandler, and on the stack during a callback, so weak retention never collects a usable one). For SslProvider.OPENSSL this lets OpenSslEngine.finalize() reclaim the native SSL* without waiting for the whole context to be collected; a leaked SslProvider.OPENSSL_REFCNT engine has no finalizer so its native memory still leaks, but it becomes collectable and so is reported by the ResourceLeakDetector rather than pinned silently.

    Entries are removed in ReferenceCountedOpenSslEngine.shutdown(), so the map does not grow in steady state. A cleared WeakReference lingers only for a leaked OPENSSL_REFCNT engine (whose SSL* is never freed, hence never reused); such a husk is tiny, dwarfed by the native memory it marks, and is deliberately left as a heap-inspectable leak signal. Do not reap it (e.g. via a ReferenceQueue): get(long) already yields null for a cleared reference, so reaping would only erase that signal.