diff --git a/common/src/main/java/org/conscrypt/ConscryptEngine.java b/common/src/main/java/org/conscrypt/ConscryptEngine.java index 2296b90fb..bf3d1c844 100644 --- a/common/src/main/java/org/conscrypt/ConscryptEngine.java +++ b/common/src/main/java/org/conscrypt/ConscryptEngine.java @@ -1681,7 +1681,13 @@ private void closeAndFreeResources() { @SuppressWarnings("deprecation") protected void finalize() throws Throwable { try { - closeAndFreeResources(); + // If ssl is null, object must not be fully constructed so nothing for us to do here. + if (ssl != null) { + // Otherwise closeAndFreeResources() and callees expect to synchronize on ssl. + synchronized (ssl) { + closeAndFreeResources(); + } + } } finally { super.finalize(); }