-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Use the parent classloader if the context classloader is a child of it. #2306
Conversation
This should only affect cases that previously would have thrown an exception. Fixes mockito#2303
There are some formatting issues that should be automatically fixed if you run |
Formatting issues fixed. |
Codecov Report
@@ Coverage Diff @@
## main #2306 +/- ##
============================================
- Coverage 84.68% 84.63% -0.06%
- Complexity 2761 2766 +5
============================================
Files 328 328
Lines 8410 8428 +18
Branches 1004 1011 +7
============================================
+ Hits 7122 7133 +11
- Misses 1008 1015 +7
Partials 280 280
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM from my side. @raphw could you double-check as well?
MockMethodInterceptor.class, | ||
MockMethodInterceptor.ForHashCode.class, | ||
MockMethodInterceptor.ForEquals.class); | ||
ClassLoader contextLoader = currentThread().getContextClassLoader(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to avoid the static import here as it's the only use and we tend to not use static imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already did this on line 99 in the current implementation, so we don't change this here. Can we clean these up in a follow-up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's figure this out in a follow-up. I think we need to reconfigure the formatter to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
src/main/java/org/mockito/internal/creation/bytebuddy/SubclassBytecodeGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/org/mockito/internal/creation/bytebuddy/SubclassBytecodeGenerator.java
Outdated
Show resolved
Hide resolved
// private methods. | ||
return true; | ||
} | ||
for (Class<?> iface : features.interfaces) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interfaces might declare interfaces of their own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's OK, as all interface methods are public, and a public interface that extends a package-private interface doesn't require the implementation to be in the same package. All that matters for the generated type is that the directly implemented interfaces are accessible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, my bad. I was thinking that you iterated over the interfaces of the class but it's of course the directly implemented ones that matter.
Thanks @charlesmunger for working on this and the regression test! |
I have since encountered two cases where this PR introduces breakage.
It turns out that the root of these problems is Sorry for the error! I'll send a PR to fix. |
This should only affect cases that previously would have thrown an
exception.
Fixes #2303