Fix resolveAndroidApiVersion when running under Robolectric#4912
Merged
akarnokd merged 1 commit intoReactiveX:1.xfrom Dec 9, 2016
Merged
Fix resolveAndroidApiVersion when running under Robolectric#4912akarnokd merged 1 commit intoReactiveX:1.xfrom
akarnokd merged 1 commit intoReactiveX:1.xfrom
Conversation
PlatformDependent.resolveAndroidApiVersion() tries to determine the Android SDK version by reading the android.os.Build$VERSION#SDK_INT field. When running under Robolectric, the class will be found (since Robolectric bundles an original android.jar). However, the method is using the system class loader for loading it (instead of the Robolectric instrumenting class loader), which will not instrument the class to run in the JVM. As a result, static initialization of the class fails with an UnsatisfiedLinkError when calling SystemProperties.get(), which calls native method native_get. I fixed by using the default class loader instead. This would only make a difference in the extremely rare case that the Android application installs a class loader that's not capable of finding Android classes. I tested that this behaves as expected on a device, fixes the issue with Robolectric, and detects it's not Android otherwise (as proven by the unit test).
Current coverage is 84.17% (diff: 100%)@@ 1.x #4912 diff @@
==========================================
Files 288 288
Lines 17808 17804 -4
Methods 0 0
Messages 0 0
Branches 2698 2697 -1
==========================================
- Hits 14992 14986 -6
- Misses 1958 1962 +4
+ Partials 858 856 -2
|
JakeWharton
approved these changes
Dec 9, 2016
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is addressing issue #4697.
PlatformDependent.resolveAndroidApiVersion()tries to determine the Android SDK version by reading theandroid.os.Build$VERSION#SDK_INTfield. When running under Robolectric, the class will be found (since Robolectric bundles an original android.jar). However, the method is using the system class loader for loading it (instead of the Robolectric instrumenting class loader), which will not instrument the class to run in the JVM. As a result, static initialization of the class fails withan UnsatisfiedLinkError when calling
SystemProperties.get(), which calls native method native_get.I fixed by using the default class loader instead. This would only make a difference in the extremely rare case that the Android application installs a class loader that's not capable of finding Android classes. I tested that this behaves as expected on a device, fixes the issue with Robolectric, and detects it's not Android otherwise (as proven by the unit test).