-
-
Notifications
You must be signed in to change notification settings - Fork 142
fix(DexFactory): register injected proxy dex with a single class loader #1968
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
Merged
+145
−33
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
67 changes: 67 additions & 0 deletions
67
test-app/app/src/main/assets/app/tests/testClassForNameDiscovery.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| describe("Tests Class.forName discovery of runtime generated classes", function () { | ||
|
|
||
| // Android framework components (e.g. FragmentFactory) resolve classes with | ||
| // Class.forName(className, false, context.getClassLoader()). Runtime generated | ||
| // proxies must be discoverable through the app's class loader, otherwise | ||
| // framework lookups crash with ClassNotFoundException (see issue #1962 / PR #1951). | ||
| // | ||
| // The extend calls below are built dynamically so the static binding generator | ||
| // cannot pre-generate the proxies and DexFactory.resolveClass takes the runtime | ||
| // generation + parent class loader injection path. | ||
| var ext = "ex" + "tend"; | ||
|
|
||
| // the app's PathClassLoader — the same loader the framework uses, | ||
| // e.g. in FragmentFactory.loadFragmentClass via context.getClassLoader() | ||
| var appClassLoader = com.tns.Runtime.class.getClassLoader(); | ||
|
|
||
| it("When_extending_a_class_at_runtime_it_should_be_discoverable_through_the_app_class_loader", function () { | ||
| var MyObject = java.lang.Object[ext]("ClassForNameDiscoveryObject", { | ||
| toString: function () { | ||
| return "discoverable"; | ||
| } | ||
| }); | ||
|
|
||
| var instance = new MyObject(); | ||
| var className = instance.getClass().getName(); | ||
|
|
||
| var found = java.lang.Class.forName(className, false, appClassLoader); | ||
|
|
||
| expect(found.getName()).toBe(className); | ||
| expect(found.equals(instance.getClass())).toBe(true); | ||
| }); | ||
|
|
||
| it("When_implementing_an_interface_at_runtime_it_should_be_discoverable_through_the_app_class_loader", function () { | ||
| var MyRunnable = java.lang.Runnable[ext]("ClassForNameDiscoveryRunnable", { | ||
| run: function () { | ||
| } | ||
| }); | ||
|
|
||
| var instance = new MyRunnable(); | ||
| var className = instance.getClass().getName(); | ||
|
|
||
| var found = java.lang.Class.forName(className, false, appClassLoader); | ||
|
|
||
| expect(found.getName()).toBe(className); | ||
| expect(found.equals(instance.getClass())).toBe(true); | ||
| }); | ||
|
|
||
| it("When_a_runtime_generated_class_is_instantiated_through_reflection_it_should_dispatch_to_the_JS_implementation", function () { | ||
| var MyObject = java.lang.Object[ext]("ClassForNameDiscoveryInstantiated", { | ||
| toString: function () { | ||
| return "created via reflection"; | ||
| } | ||
| }); | ||
|
|
||
| // make sure the implementation object is registered before Java constructs an instance | ||
| var instance = new MyObject(); | ||
| var className = instance.getClass().getName(); | ||
|
|
||
| // FragmentFactory resolves the class by name and instantiates it through | ||
| // reflection. Class.newInstance() invokes the no-arg constructor without | ||
| // the varargs marshalling getDeclaredConstructor() would need. | ||
| var found = java.lang.Class.forName(className, false, appClassLoader); | ||
| var created = found.newInstance(); | ||
|
|
||
| expect(created.toString()).toBe("created via reflection"); | ||
| }); | ||
| }); |
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
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.
Uh oh!
There was an error while loading. Please reload this page.