Skip to content
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

[Question] How to advice a class that have been intercepted by another javaagent but not loaded #829

Closed
WangSZ opened this issue Mar 24, 2020 · 4 comments
Assignees
Labels
Milestone

Comments

@WangSZ
Copy link

WangSZ commented Mar 24, 2020

[com.web.TestController] is intercepted by another javaagent and not loaded. Its not working when I advice it.

[Byte Buddy] ERROR com.web.TestController [jdk.internal.loader.ClassLoaders$AppClassLoader@2d8e6db6, unnamed module @29412871, loaded=false]
java.lang.IllegalStateException: Cannot resolve type description for com.web.TestController$auxiliary$yX8NWW70
at net.bytebuddy.pool.TypePool$Resolution$Illegal.resolve(TypePool.java:159)
	at net.bytebuddy.pool.TypePool$Default$WithLazyResolution$LazyTypeDescription.delegate(TypePool.java:914)
	at net.bytebuddy.description.type.TypeDescription$AbstractBase$OfSimpleType$WithDelegation.getModifiers(TypeDescription.java:8122)
	at net.bytebuddy.description.ModifierReviewable$AbstractBase.matchesMask(ModifierReviewable.java:618)
	at net.bytebuddy.description.ModifierReviewable$AbstractBase.isPublic(ModifierReviewable.java:336)
	at net.bytebuddy.description.type.TypeDescription$AbstractBase.isVisibleTo(TypeDescription.java:7631)
	at net.bytebuddy.matcher.VisibilityMatcher.matches(VisibilityMatcher.java:48)
	at net.bytebuddy.matcher.VisibilityMatcher.matches(VisibilityMatcher.java:27)
	at net.bytebuddy.matcher.NegatingMatcher.matches(NegatingMatcher.java:46)
	at net.bytebuddy.matcher.ErasureMatcher.matches(ErasureMatcher.java:50)
	at net.bytebuddy.matcher.ErasureMatcher.matches(ErasureMatcher.java:29)
	at net.bytebuddy.matcher.MethodParameterTypeMatcher.matches(MethodParameterTypeMatcher.java:48)
	at net.bytebuddy.matcher.MethodParameterTypeMatcher.matches(MethodParameterTypeMatcher.java:27)
	at net.bytebuddy.matcher.CollectionItemMatcher.matches(CollectionItemMatcher.java:48)
	at net.bytebuddy.matcher.CollectionItemMatcher.matches(CollectionItemMatcher.java:26)
	at net.bytebuddy.matcher.NegatingMatcher.matches(NegatingMatcher.java:46)
	at net.bytebuddy.matcher.MethodParametersMatcher.matches(MethodParametersMatcher.java:49)
	at net.bytebuddy.matcher.MethodParametersMatcher.matches(MethodParametersMatcher.java:28)
	at net.bytebuddy.matcher.ElementMatcher$Junction$Conjunction.matches(ElementMatcher.java:122)
	at net.bytebuddy.matcher.ElementMatcher$Junction$Conjunction.matches(ElementMatcher.java:122)
	at net.bytebuddy.matcher.ElementMatcher$Junction$Conjunction.matches(ElementMatcher.java:122)
	at net.bytebuddy.matcher.FilterableList$AbstractBase.filter(FilterableList.java:125)
	at net.bytebuddy.dynamic.scaffold.MethodRegistry$Default.prepare(MethodRegistry.java:505)
	at net.bytebuddy.dynamic.scaffold.inline.RedefinitionDynamicTypeBuilder.make(RedefinitionDynamicTypeBuilder.java:198)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple$Resolution.apply(AgentBuilder.java:10123)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(AgentBuilder.java:10494)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10457)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1500(AgentBuilder.java:10223)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$Java9CapableVmDispatcher.run(AgentBuilder.java:10907)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$Java9CapableVmDispatcher.run(AgentBuilder.java:10845)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10413)
	at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$ByteBuddy$ModuleSupport.transform(Unknown Source)
@WangSZ WangSZ changed the title [Question] How to advice a class that have been intercepted by another javaagent [Question] How to advice a class that have been intercepted by another javaagent but not loaded Mar 25, 2020
@raphw raphw self-assigned this Mar 25, 2020
@raphw raphw added the question label Mar 25, 2020
@raphw raphw added this to the 1.10.8 milestone Mar 25, 2020
@raphw
Copy link
Owner

raphw commented Mar 25, 2020

For your initial agent, you are injecting additional classes which are based on top of synthetic classes which are not resolvable as the class loader cannot read their class file representations.

If you want to write agents that are stackable, I recommend you to use Advice rather then MethodDelegation as it aims to enrich methods rather then replacing them.

Otherwise, you'd need to capture the byte code implementations you generate using an AgentBuilder.Listener and implement a ClassFileLocator that looks up these altered class files.

@WangSZ
Copy link
Author

WangSZ commented Mar 25, 2020

For your initial agent, you are injecting additional classes which are based on top of synthetic classes which are not resolvable as the class loader cannot read their class file representations.

If you want to write agents that are stackable, I recommend you to use Advice rather then MethodDelegation as it aims to enrich methods rather then replacing them.

Otherwise, you'd need to capture the byte code implementations you generate using an AgentBuilder.Listener and implement a ClassFileLocator that looks up these altered class files.

Thanks a lot and I`ll try a ClassFileLocator

@reallax
Copy link

reallax commented Mar 23, 2021

Otherwise, you'd need to capture the byte code implementations you generate using an AgentBuilder.Listener and implement a ClassFileLocator that looks up these altered class files.

Hi, I'm new to bytebuddy, is there any demo for the quote above?

@raphw
Copy link
Owner

raphw commented Mar 23, 2021

No, but in the listener, in the onTransform method, you receive names and byte codes of any transformed classes within the DynamicType instance provided. You would need to extract that data and make it available via the ClassFileLocator which provides names where the byte code of the classes previously supplied to the listener would be expected in return.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants