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

Allow invoking methods on an instance which is loaded by a different class loader #814

Merged
merged 1 commit into from
Jan 12, 2015

Conversation

lion7
Copy link
Contributor

@lion7 lion7 commented Dec 24, 2014

Currently an IllegalArgumentException is thrown when an implementation of the ObjectFactory interface (from cucumber-java) creates an instance of a class that is loaded by another class loader:
java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at cucumber.runtime.Utils$1.call(Utils.java:34)
... 52 more

This happens in my case where I implemented an ObjectFactory that creates an instance in an OSGi context. The OSGi framework requires the class to be loaded by a bundle's class loader and as such the class loaded is different from the class loaded by the JavaBackend (which loads the class with the system classloader).

This issue can be solved by checking if the class loader of the target instance differs from the class loader of the method's declaring class. If so the method can be retrieved from the target instance's class instead and invoked in the same way. I also added 2 tests to validate the current behavior and new behavior.

dkowis added a commit that referenced this pull request Jan 12, 2015
Allow invoking methods on an instance which is loaded by a different class loader
@dkowis dkowis merged commit bacc465 into cucumber:master Jan 12, 2015
@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants