-
-
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
NullPointerException from Groovy metaclass methods when using mockito-inline (but not mockito-core) #2522
Comments
Did you happen to find any correlation or more clues here @stevegreenn ? Adding |
Hi @stevegreenn , based on your research and some debugging, it looks to me the generator used is Inside its return subclassingRequired ? subclassEngine.mockClass(features) : features.mockedType; instead of calling the
At the same time, it seems like |
I am not 100% sure, but we might have to exempt groovy methods from the inline bytecode generator here: mockito/src/main/java/org/mockito/internal/creation/bytebuddy/InlineBytecodeGenerator.java Line 462 in cb948d2
Paging @raphw who might have more ideas. Also, @stevegreenn can you please open a PR with your regression test in a new subproject "groovyInlineTest" where we use the same configuration as "groovyTest", with the only difference that we use |
The linked line is unlikely the issue, but you are right that we probably have to ignore the meta class property accessors from Groovy also here: - similarly to what we do in the subclass mock maker. |
@stevegreenn Could you try my branch and add test subproject as a regression test as suggested? |
I have added the "Please contribute" label for anyone who would like to both include Rafaels fix, as well as the regression test provided by @stevegreenn |
@raphw @stevegreenn is this fix moving forward? Right now it seems like mockito-core users can either support static mocking by including mockito-inline, or support groovy metaclasses by excluding mockito-inline, but without a fix for this there doesn't seem to be a way to support both in the same project |
We were waiting for any Groovy user to build this branch and give quick feedback, ideally contribute a sample to Mockito's test suite. This would only take a few minutes for someone familiar with Groovy. We are happy to merge this once the functioning of this patch is confirmed! |
Apologies for the lack of presence on this issue recently. My aim is to have a pull request sorted by this weekend! |
…to-inline and Groovy
Hi @raphw checked with your branch, still same issue. Example project: https://github.com/nick-ernie/groovy-mockito-inline |
It's no surprise that this method is still there. It should simply not be instrumented. Can you run with |
Speaking of, I got fooled by my own APIs. Can you try again? I just amended my branch. |
@raphw checked with updated branch, same issue, dumps attached Tried with groovy (3 and 4) and java(8 and 17). |
When I check the *groovy.lang.GroovyObject I ammended my branch, please try it! |
@raphw, tried both on java 8 and 17 with new branch, now see the following error:
|
That's particular? And the same error did not occur before? Are you using a specific JDK for this? It seems to me as if this stack is lacking the root error. |
@raphw , no the error what i see before not appearing now, It appears as if your JDK does not supply a working agent attachment mechanism.
Caused by: java.lang.IllegalStateException: The class loader responsible for looking up the resource: sun.misc.Launcher$AppClassLoader@73d16e93 and on java 17 with following one: It appears as if your JDK does not supply a working agent attachment mechanism.
Caused by: java.lang.IllegalStateException: The class loader responsible for looking up the resource: jdk.internal.loader.ClassLoaders$AppClassLoader@5ffd2b27 |
That is strange, the file is normally renamed during build. But I wonder if this has to do with the exection context. @TimvdLippe Any ideas? |
@nick-ernie Can you clear your Gradle build cache and see if it is resolved? I think that should be in |
@raphw @TimvdLippe after playing a little bit with build of mockito, i can see now .raw file, thanks. |
@raphw Any idea when this fix will be available in a released version of Mockito? |
Still waiting for this rebasing but it's practically ready: #2566 |
Hey Mockito team,
I'm working on a project where we've dropped the usage of PowerMock in favour of
mockStatic
frommockito-inline
but unfortunately this has led to an issue.The issue seems to be the same as #2204. An outcome of that issue was the following test: https://github.com/mockito/mockito/blob/main/subprojects/groovyTest/src/test/groovy/org/mockito/groovy/GroovyMockitoTest.groovy
I've copied this into my project and this test is actually failing. I can make the test pass by replacing the dependency of
mockito-inline
withmockito-core
but then I'd lose the ability to mock static/finals.Versions:
The output of the failing test:
Here is the failing test isolated in a small Gradle project: https://github.com/stevegreenn/mockito-inline-issue
Any ideas?
Many thanks,
Steve
The text was updated successfully, but these errors were encountered: