Adding a declaresMethod matcher to a AgentBuilder#type matcher makes method matchers fail
See original GitHub issueI’d like to use declaresMethod matchers before hasSuperType matchers in order to pre-filter classes that don’t declare the method I want to instrument before applying the hasSuperType matcher, which is more expensive.
Unfortunately, using the declaresMethod matcher seems to mess with the method matcher (net.bytebuddy.agent.builder.AgentBuilder.Transformer.ForAdvice#advice(net.bytebuddy.matcher.ElementMatcher<? super net.bytebuddy.description.method.MethodDescription>, java.lang.String))
When adding .and(declaresMethod(any())) after line 76, the test co.elastic.apm.servlet.AsyncServletTest#testAsync fails. The logs tell me that I still get a type match, but I don’t get a method match anymore.
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (12 by maintainers)
Top Results From Across the Web
NPE in Mockito argument matcher with doReturn causing all ...
While using argument matchers, Mockito states that to match a primitive type we ... If I run the whole class, then all methods...
Read more >Mockito Argument Matchers - any(), eq() - DigitalOcean
If we want to use a specific value for an argument, then we can use eq() method. when(mockFoo.bool(eq("false"), anyInt(), any(Object.class))).
Read more >`respond_to` matcher - RSpec Expectations - Relish
Use the respond_to matcher to specify details of an object's interface. ... If the number of arguments accepted by the method is important...
Read more >Matchers - jMock
An expectation that uses parameter matchers must use the "with" method to wrap every parameter, whether a matcher function or a literal value....
Read more >Index (JUnit API)
Static method in class org.hamcrest.core.AllOf: Creates a matcher that matches if the examined object matches ALL of the specified matchers.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I see that can be a problem, especially in small environments, but in the end its a trade off between speed and memory as in any application.
Same problem happened to my project. My plan is to call
target.getDeclaredTypes()andtarget.getDeclaredFields()to load all the classes used by the target class during the matcher executing. But it did not work. Is the matcher-excuting a part of the class file transformation? @raphwSo that I have to make another way to load the class before actual class-transformation. A empty class file transformer installed for loading class as the last solution. Here is the demo.
Cause I can not load class by the class name for some reasons, so it works perfect for me. Is there more effective and elegant way?