On a test that uses Volley, with @Config(sdk = 19 ...) we see the following error. android.net.Network was introduced in API 21 so the code path that loads this class is being invoked incorrectly.
@cermak this was exposed by your PR https://github.com/robolectric/robolectric/pull/2206 which looks correct, but it does have the side effect of failing because there is no @Implements annotation on the stub Shadow. I suspect this code path was always being erroneously invoked but now it is exposed.
Exception in thread "Thread-9" java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:265)
at com.squareup.okhttp.internal.Platform.findPlatform(Platform.java:136)
at com.squareup.okhttp.internal.Platform.<clinit>(Platform.java:56)
at com.squareup.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:137)
at com.squareup.okhttp.internal.io.RealConnection.connect(RealConnection.java:108)
at com.squareup.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)
at com.squareup.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
at com.squareup.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:450)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:399)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:527)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:109)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
Caused by: java.lang.IllegalArgumentException: class org.robolectric.shadows.ShadowNetwork is not annotated with @Implements
at org.robolectric.internal.bytecode.ShadowMap.getShadowInfo(ShadowMap.java:65)
at org.robolectric.internal.bytecode.ShadowMap.get(ShadowMap.java:37)
at org.robolectric.internal.bytecode.ShadowWrangler.getShadowConfig(ShadowWrangler.java:221)
at org.robolectric.internal.bytecode.ShadowWrangler.findDirectShadowClass(ShadowWrangler.java:490)
at org.robolectric.internal.bytecode.ShadowWrangler.classInitializing(ShadowWrangler.java:103)
at org.robolectric.internal.bytecode.RobolectricInternals.classInitializing(RobolectricInternals.java:18)
at android.net.Network.<clinit>(Network.java)
... 17 more
Anyone come across this issue try annotate your test to use sdk 23
@Config(sdk = 23)
@RunWith(RobolectricTestRunner.class)
public class SampleTest {
...
}
Closing this as it hasn't been updated in a while. If its still an issue with Robolectric 4.0 please reopen with a reproducible test case and we'll prioritize.
Most helpful comment
Anyone come across this issue try annotate your test to use
sdk 23