NoSuchAlgorithmException when using PowerMockito


July 29, 2019

NoSuchAlgorithmException when using PowerMockito

So today i was making some changes to one of our services to add better support for rate limiting. I made all the changes and i was happy; but when i ran the tests to verify everything before i committed it. I was confronted with:

org.apache.http.ssl.SSLInitializationException: class configured for SSLContext:$TLSContext not a SSLContext
at org.apache.http.ssl.SSLContexts.createDefault(
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.getSocketFactory(
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.getDefaultRegistry(
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(
... 40 more
Caused by: class configured for SSLContext:$TLSContext not a SSLContext
at java.base/
at java.base/
at java.base/
at org.apache.http.ssl.SSLContexts.createDefault(
... 44 more


I had not changed the test that was triggering the error, also the error is deep within Java and Apache HttpClient. It turns out the test in question is using PowerMockito to mock some legacy static functions for testing. This seems to have the side effect of affecting the class loader used to load the SSLContextSpi class used to verify the SSLContext type in the SSLContextFactory.


A quick google found that the solution is to exclude the* package from the PowerMock system. This can be done by adding the @PowerMockIgnore annotation to the test class. I added the following to the test and it resolved the problem.

@PowerMockIgnore({ "*" })

Experienced developer in various languages, currently a product owner of leading the back end architecture.