When a test attempts to instantiate MockWebServer this exception is thrown:
Caused by: java.lang.NullPointerException: No password supplied for PKCS#12 KeyStore.
at org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.engineLoad(Unknown Source)
at java.base/java.security.KeyStore.load(KeyStore.java:1479)
at java.base/sun.security.ssl.TrustStoreManager$TrustAnchorManager.loadKeyStore(TrustStoreManager.java:365)
at java.base/sun.security.ssl.TrustStoreManager$TrustAnchorManager.getTrustedCerts(TrustStoreManager.java:313)
at java.base/sun.security.ssl.TrustStoreManager.getTrustedCerts(TrustStoreManager.java:55)
at java.base/sun.security.ssl.TrustManagerFactoryImpl.engineInit(TrustManagerFactoryImpl.java:49)
at java.base/javax.net.ssl.TrustManagerFactory.init(TrustManagerFactory.java:278)
at okhttp3.internal.Util.platformTrustManager(Util.java:666)
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:257)
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:231)
at okhttp3.internal.Internal.initializeInstanceForTests(Internal.java:44)
at okhttp3.mockwebserver.MockWebServer.<clinit>(MockWebServer.java:103)
... 17 more
The same test passes when using JUnit4 runner instead of AndroidJUnit4. Any suggestions or ideas for debugging is greatly appreciated.
Create a Robolectric test that attempts to instantiate MockWebServer with its no-arg constructor: MockWebServer()
Robolectric 4.3
Android 28
Java 9 (and 11)
MockWebServer 3.14.2
macOS 10.14.5
I will provide one if necessary.
After trying many things I finally found one workaround:
System.setProperty("javax.net.ssl.trustStore", "NONE")
MockWebServer()
The tests are passing with this additional configuration.
I think I found the root cause of this problem. Try doing:
-Djavax.net.ssl.trustStoreType=JKS
or
System.setProperty("javax.net.ssl.trustStoreType", "JKS")
MockWebServer()
This works for me too. This seems like something Robolectric should be configuring to emulate the Android environment more closely. I'll let the project maintainers decide whether this issue is worth fixing.
This should be fixed with 4.4 (specifically #5849)
Most helpful comment
After trying many things I finally found one workaround:
The tests are passing with this additional configuration.