question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MethodCall.resolve() does not apply ElementMatcher to private methods in a DynamicType under construction

See original GitHub issue

I will try to refine this bug report as I learn more. I thought it was worth filing anyway because ElementMatchers are used so much and are so central to ByteBuddy.

I’m defining a DynamicType. As part of doing this, I am defining two private methods: produce and inject.

At one point in my program I do this:

MethodCall.invoke(ElementMatchers.named("inject"))...

…i.e. “please invoke the inject method I defined elsewhere in this dynamic type”.

I get an exception indicating that (as it happens) two methods (!) meet this criteria (even though I’ve only defined one inject method). When I debug into the resolution code, I see that my produce method has somehow matched the ElementMatchers.named("inject") matcher. I’m not sure how this can happen.

I’m attaching a NetBeans debugger screenshot showing MethodCall.java at line 812. Here, candidates.size() is 2. You can see that the matcher is name(equals(inject)) and one of the two candidates is produce.

Screen Shot 2021-01-30 at 11 13 52 AM

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
raphwcommented, Feb 2, 2021

Silly me pushed it to an unrelated branch, thanks for noticing!

0reactions
ljnelsoncommented, Feb 2, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Call private methods and private properties from outside a ...
As of PHP 7, you can use the new Closure::call method, to bind any method/property of an obect to a callback function, even...
Read more >
net.bytebuddy.matcher.ElementMatchers java code examples
Only matches the {@link Object#toString()} method, also if it was overridden. ... T> cls = new ByteBuddy() .subclass(interfaceType) .method(ElementMatchers.
Read more >
Use C# dynamic typing to conveniently access internals of an ...
You can call static methods by creating an ExposedClass over the class. For example, let's call the private File.InternalExists() static method:
Read more >
How do you unit test private methods?
You generally don't unit test private methods directly. Since they are private, consider them an implementation detail. Nobody is ever going ...
Read more >
Mocking Private, Static and Void Methods Using Mockito
We have created a new method called – calculatePriceWithPrivateMethod, which calls a private method inside the same class and returns whether ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found