Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SandboxClassLoader to obey parent-first contract #2905

Merged
merged 2 commits into from Feb 22, 2017

Conversation

xian
Copy link
Member

@xian xian commented Feb 11, 2017

Fixes #2208.
Fixes #2677.

@xian xian added this to the 3.3 milestone Feb 11, 2017
@xian xian added the defect label Feb 11, 2017
@xian xian force-pushed the classloader-correctness branch 2 times, most recently from b5e5fc0 to 697cc52 Compare February 22, 2017 01:16
@xian xian requested a review from jongerrish February 22, 2017 01:23
Supports PowerMock and experimental Mockito mode which enables mocking final classes/methods.
Supports Package.getPackage().
Copy link
Contributor

@jongerrish jongerrish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, one of the longest running Robolectric issues fixed? :-D

// See https://github.com/robolectric/robolectric/issues/521
if (name.startsWith("android.R")) {
// android.R and com.android.internal.R classes must be loaded from the framework jar
if (name.matches("(android|com\\.android\\.internal)\\.R(\\$.+)?")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name.startsWith("android.R) || name.startsWith("com.android.internal.R") may be more clear here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're pretty confident there'll never be an android.Riboflavin or com.android.internal.Roustabout or something? :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think so, although, you can never say never :-D I think this will go away when we check the jar as the source of truth for what to acquire though anyway, so I'm not fussed about this :-)

ReflectionHelpers.setStaticField(androidBuildVersionClass, "SDK_INT", sdkConfig.getApiLevel());
ReflectionHelpers.setStaticField(androidBuildVersionClass, "RELEASE", sdkConfig.getAndroidVersion());

PackageResourceTable systemResourceTable = sdkEnvironment.getSystemResourceTable(getJarResolver());
PackageResourceTable systemResourceTable = (sdkEnvironment).getSystemResourceTable(getJarResolver());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extraneous parens around (sdkEnvironment) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, fixed!

@@ -107,6 +107,11 @@ public void testVersionConfiguration() {
.isEqualTo("4.4_r1");
}


@Test public void assertThatz() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to do this more? I'm guessing that it is checking that things are loaded from the right classloader, but I'm a little confused as its an assert for a primitive rather than an object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the test name. I came across a classloader conflict because org.junit.Assert loads some hamcrest things.

@xian
Copy link
Member Author

xian commented Feb 22, 2017

Dogfood green! :-)

@xian xian merged commit c3a3b77 into master Feb 22, 2017
@jongerrish
Copy link
Contributor

jongerrish commented Feb 24, 2017 via email

@YorkShen
Copy link

YorkShen commented Mar 2, 2017

Well done.

@@ -75,8 +75,7 @@
private final SdkPicker sdkPicker;
private final ConfigMerger configMerger;

private TestLifecycle<Application> testLifecycle;
private DependencyResolver dependencyResolver;
private transient DependencyResolver dependencyResolver;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is dependencyResolver transient?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants