Want to contribute a bugfix

2 views
Skip to first unread message

Charles Munger

unread,
Mar 14, 2018, 8:59:29 PM3/14/18
to mockito-dev
I've waded through a bunch of the classloading machinery in mockito 1.9.5 to fix a bug with multiple overlapping classloaders - https://github.com/mockito/mockito/issues/1297

Would a fix be welcome on the 1.9.5 branch? Or perhaps someone can draw inspiration from it to fix the same issue on the 2.x branch? I'm happy to provide details on the (somewhat involved) root cause.

Tim van der Lippe

unread,
Mar 15, 2018, 6:16:37 AM3/15/18
to mocki...@googlegroups.com
We prefer not to update Mockito 1 any longer (even more so, I am not sure how we even can). A bugfix to 2.x (if the issue still persists) would be greatly appreciated though!

Op do 15 mrt. 2018 om 01:59 schreef Charles Munger <charles...@gmail.com>:
I've waded through a bunch of the classloading machinery in mockito 1.9.5 to fix a bug with multiple overlapping classloaders - https://github.com/mockito/mockito/issues/1297

Would a fix be welcome on the 1.9.5 branch? Or perhaps someone can draw inspiration from it to fix the same issue on the 2.x branch? I'm happy to provide details on the (somewhat involved) root cause.

--
You received this message because you are subscribed to the Google Groups "mockito-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito-dev...@googlegroups.com.
To post to this group, send email to mocki...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito-dev.
For more options, visit https://groups.google.com/d/optout.

Szczepan Faber

unread,
Mar 15, 2018, 10:40:19 AM3/15/18
to mocki...@googlegroups.com
+1 to Tim's

Thank you Charles for reaching out!

On Thu, Mar 15, 2018 at 3:16 AM, Tim van der Lippe <tvande...@gmail.com> wrote:
We prefer not to update Mockito 1 any longer (even more so, I am not sure how we even can). A bugfix to 2.x (if the issue still persists) would be greatly appreciated though!

Op do 15 mrt. 2018 om 01:59 schreef Charles Munger <charles...@gmail.com>:
I've waded through a bunch of the classloading machinery in mockito 1.9.5 to fix a bug with multiple overlapping classloaders - https://github.com/mockito/mockito/issues/1297

Would a fix be welcome on the 1.9.5 branch? Or perhaps someone can draw inspiration from it to fix the same issue on the 2.x branch? I'm happy to provide details on the (somewhat involved) root cause.

--
You received this message because you are subscribed to the Google Groups "mockito-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito-dev+unsubscribe@googlegroups.com.

To post to this group, send email to mocki...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito-dev.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mockito-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito-dev+unsubscribe@googlegroups.com.

To post to this group, send email to mocki...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito-dev.
For more options, visit https://groups.google.com/d/optout.



--
Szczepan Faber
Creator of Mockito | Tech Lead at LinkedIn | Maker of Open Source on GitHub
Check out how to give great code reviews. You will be glad you did!

Charles Munger

unread,
Mar 16, 2018, 11:58:09 PM3/16/18
to mocki...@googlegroups.com
I'm not so familiar with gradle, can anyone help me with setting up this test:

Thread.currentThread().setContextClassLoader(<UrlClassLoader with same parent and classpath as current classloader>);
Foo foo = Mockito.mock(Foo.class);


interface Foo {
  void doSomething();
}

With a mockito-extensions file pointing to a custom mockmaker that simply forwards to the default one (ByteBuddyMockMaker?). 

Mockito uses the context classloader to load the custom mockmaker, which is capable of providing all the mockito classes since it shares the same classpath as the system classloader; but the cast to MockAccess fails, because the instantiated mock implements MockAccess from the first classloader, since (at least in 1.9.5) the classloaders passed in to SearchingClassLoader are simply checked in order; the first one to return a class wins. I believe MultipleParentClassLoader has this same issue.

Code pointers, examples, or an @Ignored checked in test are all welcome - the fix is as simple as storing a Map<String, Class<?>> that caches the instances of classes used internally by the mockmaker, so that MockHandler and the classes it references always use the mockmaker's classloader.

--
You received this message because you are subscribed to a topic in the Google Groups "mockito-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mockito-dev/djoJxKAigIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mockito-dev+unsubscribe@googlegroups.com.

Tim van der Lippe

unread,
Mar 17, 2018, 4:48:01 AM3/17/18
to mocki...@googlegroups.com
Feel free to open a PR and we can take a look.

On Sat, 17 Mar 2018, 04:58 Charles Munger, <charles...@gmail.com> wrote:
I'm not so familiar with gradle, can anyone help me with setting up this test:

Thread.currentThread().setContextClassLoader(<UrlClassLoader with same parent and classpath as current classloader>);
Foo foo = Mockito.mock(Foo.class);


interface Foo {
  void doSomething();
}

With a mockito-extensions file pointing to a custom mockmaker that simply forwards to the default one (ByteBuddyMockMaker?). 

Mockito uses the context classloader to load the custom mockmaker, which is capable of providing all the mockito classes since it shares the same classpath as the system classloader; but the cast to MockAccess fails, because the instantiated mock implements MockAccess from the first classloader, since (at least in 1.9.5) the classloaders passed in to SearchingClassLoader are simply checked in order; the first one to return a class wins. I believe MultipleParentClassLoader has this same issue.

Code pointers, examples, or an @Ignored checked in test are all welcome - the fix is as simple as storing a Map<String, Class<?>> that caches the instances of classes used internally by the mockmaker, so that MockHandler and the classes it references always use the mockmaker's classloader.

On Thu, Mar 15, 2018 at 7:40 AM, Szczepan Faber <szcz...@gmail.com> wrote:
+1 to Tim's

Thank you Charles for reaching out!
On Thu, Mar 15, 2018 at 3:16 AM, Tim van der Lippe <tvande...@gmail.com> wrote:
We prefer not to update Mockito 1 any longer (even more so, I am not sure how we even can). A bugfix to 2.x (if the issue still persists) would be greatly appreciated though!

Op do 15 mrt. 2018 om 01:59 schreef Charles Munger <charles...@gmail.com>:
I've waded through a bunch of the classloading machinery in mockito 1.9.5 to fix a bug with multiple overlapping classloaders - https://github.com/mockito/mockito/issues/1297

Would a fix be welcome on the 1.9.5 branch? Or perhaps someone can draw inspiration from it to fix the same issue on the 2.x branch? I'm happy to provide details on the (somewhat involved) root cause.

--
You received this message because you are subscribed to the Google Groups "mockito-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito-dev...@googlegroups.com.

To post to this group, send email to mocki...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito-dev.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mockito-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito-dev...@googlegroups.com.

To post to this group, send email to mocki...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito-dev.
For more options, visit https://groups.google.com/d/optout.



--
Szczepan Faber
Creator of Mockito | Tech Lead at LinkedIn | Maker of Open Source on GitHub
Check out how to give great code reviews. You will be glad you did!

--
You received this message because you are subscribed to a topic in the Google Groups "mockito-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mockito-dev/djoJxKAigIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mockito-dev...@googlegroups.com.

To post to this group, send email to mocki...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito-dev.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mockito-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito-dev...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages