`isCleartextTrafficPermitted()` fails on OpenJDK 8 + Robolectric
See original GitHub issueHow 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.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:17
- Comments:39 (15 by maintainers)
Top Results From Across the Web
Robolectric test fails when trying to inflate layout that has a ...
getApplicationContext() . The ApplicationContext has no theme at all, using an Activity 's Context suggested (which will always have the current ...
Read more >Diff - platform/libcore - Google Git
Used for nullability annotations in OpenJDK source. droiddoc_exported_dir ... ErrnoException; method public static int setsid() throws android.system.
Read more >Category: ElectricSpock - u-ryo's blog
これは、 isCleartextTrafficPermitted() fails on OpenJDK 8 + Robolectric #2533にあるように、 NetworkSecurityPolicy をShadowしてやればよい。
Read more >NetworkSecurityPolicy - Android Developers
The policy currently consists of a single flag: whether cleartext network traffic is permitted. See isCleartextTrafficPermitted() .
Read more >Testing Jetpack Security with Robolectric | by Matthew Dolan
You can then read and write encrypted data seamlessly as if it were a normal SharedPreferences file. sharedPreferences.edit().apply { putString( ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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,