As of Mockito 2.2.17, the issue fixed in #695 is broken again. The test case in that ticket now fails once more. I assume this is due to the fix in #757. @raphw, can you please have a look? :)
NB: I opened a new ticket, as I consider released tickets to be immutable. If you feel differently, let me know and next time I'll reopen an existing ticket if applicable.
Oh no, I even added a specific test case for retaining the parameters. This is very strange as the test case works. I will have a look!
So, the interesting thing is that the problem looks like this right now:
class Foo {
public Foo(String x) { }
void qux(String x) { }
}
System.out.println(Foo.class.getDeclaredConstructor(String.class).getParameters()[0].getName());
System.out.println(Foo.class.getDeclaredMethod("qux", String.class).getParameters()[0].getName());
Foo foo = mock(Foo.class);
System.out.println(Foo.class.getDeclaredConstructor(String.class).getParameters()[0].getName());
System.out.println(Foo.class.getDeclaredMethod("qux", String.class).getParameters()[0].getName());
This will only retain parameters for the constructor. It looks like the sometimes-buggy instrumentation API sometimes does retain parameter names and writing them twice is then causing the parameter name to be suppressed.
I need to solve this properly. I will probably add some convenience to Byte Buddy and solve it there. Give me a few days, thanks for the report!
Cool, no worries! Version 2.2.16 works just fine for us, so there's no hurry.
@raphw out of curiosity - do I understand correctly from this thread that
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8168623 is not always happening?
Just upgraded to Mockito 2.2.21 and can confirm the fix works for us. Thanks @raphw!
Great, I figured out why it worked sometimes. Byte Buddy automatically fixed the parameters for non-intercepted metgods, i.e.constructor as it read them from the loaded original class. Outsmarted myself there.