didi/DoKit · error · IllegalArgumentException

sslSocketFactory == null

Error message

sslSocketFactory == null

What it means

setSSLSocketFactory() rejects a null factory with IllegalArgumentException("sslSocketFactory == null") — HttpsURLConnection's contract requires a non-null SSLSocketFactory. The wrapper then pairs the factory with a trust manager and rebuilds the OkHttp client, so a null value cannot proceed.

Source

Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/aop/urlconnection/ObsoleteUrlFactory.java:1312

            return delegate.handshake;
        }

        @Override
        public void setHostnameVerifier(HostnameVerifier hostnameVerifier) {
            delegate.client = delegate.client.newBuilder()
                    .hostnameVerifier(hostnameVerifier)
                    .build();
        }

        @Override
        public HostnameVerifier getHostnameVerifier() {
            return delegate.client.hostnameVerifier();
        }

        @Override
        public void setSSLSocketFactory(SSLSocketFactory sslSocketFactory) {
            if (sslSocketFactory == null) {
                throw new IllegalArgumentException("sslSocketFactory == null");
            }

            X509TrustManager trustManager = new MyTrustManager().getTrustManager();
            // This fails in JDK 9 because OkHttp is unable to extract the trust manager.
            delegate.client = delegate.client.newBuilder()
                .sslSocketFactory(sslSocketFactory, trustManager)
                .build();
        }


        @Override
        public SSLSocketFactory getSSLSocketFactory() {
            return delegate.client.sslSocketFactory();
        }
    }

    static final class UnexpectedException extends IOException {
        static final Interceptor INTERCEPTOR = new Interceptor() {

View on GitHub (pinned to 626827cddb)

Solutions

  1. Null-check the factory and skip the call when null (the default factory remains in use).
  2. Build the SSLSocketFactory from an SSLContext initialized with a real key/trust manager; never default it to null.
  3. If disabling custom TLS, call conn.setSSLSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault()) instead of null.

Example fix

// before
conn.setSSLSocketFactory(config.getSslFactory()); // may be null -> IAE

// after
SSLSocketFactory f = config.getSslFactory();
if (f != null) conn.setSSLSocketFactory(f);
Defensive patterns

Strategy: validation

Validate before calling

SSLSocketFactory f = customFactory != null ? customFactory : (SSLSocketFactory) SSLSocketFactory.getDefault();
conn.setSSLSocketFactory(f);

Prevention

When it happens

Trigger: Calling setSSLSocketFactory(null) directly, or passing a nullable custom factory variable (e.g. from config or an SSLContext that failed to initialize and returned null).

Common situations: Optional TLS config where the custom factory is only built when settings exist; SSLContext.getInstance(...).getSocketFactory() guarded incorrectly; passing a config object whose factory field is unset.

Related errors


AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14). Data as JSON: /api/errors/fa692c603e9bda3e. Report an issue: GitHub.