okhttp: `isCleartextTrafficPermitted()` fails on OpenJDK 8 + Robolectric
How to reproduce:
- Install OpenJDK 8
- Use current 3.3.0-SNAPSHOT version
new OkHttpClient()
: The code fails in the static initializer, when trying to figure out the platform.
The code that breaks was introduced here: https://github.com/square/okhttp/issues/2513
Either the detection of the runtime is broken, or the code is wrong there. I’ll try to figure out an automatic test for this.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 17
- Comments: 39 (15 by maintainers)
Commits related to this issue
- Upgrade Robolectric to v3.1 and API to Marshmallow Upgrade Robolectric to v3.1[0]. Also, upgrade the test API to v23 since that seems to be compatible with OkHttp v3.3.1[1]. [0] https://github.com/r... — committed to wikimedia/apps-android-wikipedia by niedzielski 8 years ago
- Update OkHttp to 3.4.0 and Okio to 1.9.0 Summary: - 3.3.1 wasn't compatible with Robolectric 3.0, however 3.4.0 [fixes](https://github.com/square/okhttp/issues/2533#issuecomment-230198063) this issue... — committed to facebook/react-native by AndrewJack 8 years ago
- Update OkHttp to 3.4.0 and Okio to 1.9.0 Summary: - 3.3.1 wasn't compatible with Robolectric 3.0, however 3.4.0 [fixes](https://github.com/square/okhttp/issues/2533#issuecomment-230198063) this issue... — committed to fadils/react-native by AndrewJack 8 years ago
- Update OkHttp to 3.4.0 and Okio to 1.9.0 Summary: - 3.3.1 wasn't compatible with Robolectric 3.0, however 3.4.0 [fixes](https://github.com/square/okhttp/issues/2533#issuecomment-230198063) this issue... — committed to iodine/react-native by AndrewJack 8 years ago
- Update OkHttp to 3.4.0 and Okio to 1.9.0 Summary: - 3.3.1 wasn't compatible with Robolectric 3.0, however 3.4.0 [fixes](https://github.com/square/okhttp/issues/2533#issuecomment-230198063) this issue... — committed to HomePass/react-native by AndrewJack 8 years ago
- robo fixed https://github.com/square/okhttp/issues/2533 — committed to aafa/bitrader by aafa 8 years ago
- Update OkHttp to 3.4.0 and Okio to 1.9.0 Summary: - 3.3.1 wasn't compatible with Robolectric 3.0, however 3.4.0 [fixes](https://github.com/square/okhttp/issues/2533#issuecomment-230198063) this issue... — committed to tungdo194/rn-test by AndrewJack 8 years ago
I was able to get the test green. Here’s what I did:
As for why it works, I don’t know. It appears the default SDK is 21. The bit I don’t understand is why it isn’t throwing a ClassNotFoundException given this class is only in SDK 23. The test project itself is depending on API 23, which may have something to do with it.
Ouch. This (hideous) workaround also appears functional with 3.0,
Happens with OkHttp 3.5.0 and robolectric 3.1.4
Oh, It works if you add a
String
argument to theisCleartetTrafficPermitted
shadow method. Here’s the updated (hideous) workaround:A truly terrible hack for those who can’t upgrade to Robolectric 3+ is to add the following class to your test module under the
android.security
package. Probably not a good idea if you’re testing the actualNetworkSecurityPolicy
.I’m getting
with okhttp 3.3.1 and both robolectric 3.0 and 3.1-rc1 all good with okhttp 3.2.+