{"record":{"id":"fa692c603e9bda3e","repo":"didi/DoKit","slug":"sslsocketfactory-null","errorCode":null,"errorMessage":"sslSocketFactory == null","messagePattern":"sslSocketFactory == null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/aop/urlconnection/ObsoleteUrlFactory.java","lineNumber":1312,"sourceCode":"            return delegate.handshake;\n        }\n\n        @Override\n        public void setHostnameVerifier(HostnameVerifier hostnameVerifier) {\n            delegate.client = delegate.client.newBuilder()\n                    .hostnameVerifier(hostnameVerifier)\n                    .build();\n        }\n\n        @Override\n        public HostnameVerifier getHostnameVerifier() {\n            return delegate.client.hostnameVerifier();\n        }\n\n        @Override\n        public void setSSLSocketFactory(SSLSocketFactory sslSocketFactory) {\n            if (sslSocketFactory == null) {\n                throw new IllegalArgumentException(\"sslSocketFactory == null\");\n            }\n\n            X509TrustManager trustManager = new MyTrustManager().getTrustManager();\n            // This fails in JDK 9 because OkHttp is unable to extract the trust manager.\n            delegate.client = delegate.client.newBuilder()\n                .sslSocketFactory(sslSocketFactory, trustManager)\n                .build();\n        }\n\n\n        @Override\n        public SSLSocketFactory getSSLSocketFactory() {\n            return delegate.client.sslSocketFactory();\n        }\n    }\n\n    static final class UnexpectedException extends IOException {\n        static final Interceptor INTERCEPTOR = new Interceptor() {","sourceCodeStart":1294,"sourceCodeEnd":1330,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/aop/urlconnection/ObsoleteUrlFactory.java#L1294-L1330","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Null-check the factory and skip the call when null (the default factory remains in use).","Build the SSLSocketFactory from an SSLContext initialized with a real key/trust manager; never default it to null.","If disabling custom TLS, call conn.setSSLSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault()) instead of null."],"exampleFix":"// before\nconn.setSSLSocketFactory(config.getSslFactory()); // may be null -> IAE\n\n// after\nSSLSocketFactory f = config.getSslFactory();\nif (f != null) conn.setSSLSocketFactory(f);","handlingStrategy":"validation","validationCode":"SSLSocketFactory f = customFactory != null ? customFactory : (SSLSocketFactory) SSLSocketFactory.getDefault();\nconn.setSSLSocketFactory(f);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard every setSSLSocketFactory call with a null check.","Build factories from a properly initialized SSLContext; treat a null factory as a config error, not a default."],"tags":["network","https","tls","null-safety"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}