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
Stacktraces of exceptions are trimmed too much #2238
Comments
Thanks for reporting this issue! We would welcome a patch + regression test for this issue. |
Thanks for your great work on Mockito and the contribution to open source it continues to make. I've come across the very same behavior under a similar setup. |
Unfortunately, this fix broke one of my tests. The fixed code hides much more stack trace elements than before which breaks my production logic due to missing some important frames. The exception is thrown by My original stack trace (shortened):
My stack trace after processing (complete):
Notice that |
Hi,
I'm not sure if this is a bug or an intended behaviour.
When testing a method which throws an exception (checked or unchecked), the causing line is suppressed in the stack coming from Mockito.
Simple example:
When calling 'message()' on the spy (same happens on a full mock as well), I would expect to see line 17 in the exception cause.
Instead I see this:
Line 15 contains 'System.out.println', which is not causing the exception, but is the first expression inside of the method 'message()'.
I debugged this behaviour and came to
org.mockito.internal.creation.bytebuddy.MockMethodAdvice.hideRecursiveCall(Throwable, int, Class<?>)
which seems to be the root cause for this.
The stack trace given to that method includes the correct line (line 17 in this case).
My stack trace in this case has 18 entries in total:
When the method is finished, 13 entries are left and the most important entry is missing:
Disabling "cleansStackTrace" using MockitoConfiguration does not help - hideRecursiveCall is always called.
This bug/feature is very annoying when testing methods which may throw the same type of exception at different locations.
Eg. in my case I know that the exception was thrown in that very method, but I don't know if it happens in e.g. line 20 or 85.
Same thing happens to
RuntimeException
s, which is also annoying... Seeing a NullPointerException without knowing where it happens is not helpful.Is there any (configuration) option to disable the 'cleaning' of the stack trace completely?
Any chance of getting this fixed?
Tested Mockito versions: 3.6.0 and 3.8.0
OS: Linux/Ubuntu 20.04 64-Bit
JDK: OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9+11)
The text was updated successfully, but these errors were encountered: