我Cannot resolve type description
在为. AgentBuilder.Listener.onError(...)
_AgentBuilder
Instrumentation
代理代码为:
public static void premain(final String agentArgs, final Instrumentation inst) {
System.out.println("from bytebuddy: agent premain");
new AgentBuilder.Default(new ByteBuddy().with(TypeValidation.DISABLED))
.disableClassFormatChanges()
.ignore(none())
.with(RedefinitionStrategy.RETRANSFORMATION)
.with(InitializationStrategy.NoOp.INSTANCE)
.with(TypeStrategy.Default.REDEFINE)
.with(new AgentBuilder.Listener() {
public void onDiscovery(final String typeName, final ClassLoader classLoader, final JavaModule module, final boolean loaded) {
log("Event::onDiscovery(" + typeName + ", " + getNameId(classLoader) + ", " + module + ", " + loaded + ")");
}
public void onTransformation(final TypeDescription typeDescription, final ClassLoader classLoader, final JavaModule module, final boolean loaded, final DynamicType dynamicType) {
log("Event::onTransformation(" + typeDescription.getName() + ", " + getNameId(classLoader) + ", " + module + ", " + loaded + ", " + dynamicType + ")");
}
public void onIgnored(final TypeDescription typeDescription, final ClassLoader classLoader, final JavaModule module, final boolean loaded) {
log("Event::onIgnored(" + typeDescription.getName() + ", " + getNameId(classLoader) + ", " + module + ", " + loaded + ")");
}
public void onError(final String typeName, final ClassLoader classLoader, final JavaModule module, final boolean loaded, final Throwable throwable) {
log("Event::onError(" + typeName + ", " + getNameId(classLoader) + ", " + module + ", " + loaded + ")", throwable);
}
public void onComplete(final String typeName, final ClassLoader classLoader, final JavaModule module, final boolean loaded) {
log("Event::onComplete(" + typeName + ", " + getNameId(classLoader) + ", " + module + ", " + loaded + ")");
}
})
.type(hasSuperType(named("com.ning.http.client.AsyncHttpClientConfig$Builder")))
.transform(new Transformer() {
public DynamicType.Builder<?> transform(final DynamicType.Builder<?> builder, final
System.out.println("from bytebuddy: transform");
TypeDescription typeDescription, final ClassLoader classLoader, final JavaModule module) {
return builder.visit(Advice.to(AHCBuilderExit.class).on(isDefaultConstructor()));
}})
.installOn(inst);
}
这是使用 ByteBuddy v1.10.2 和 Mule 4 (jdk1.8) 作为目标应用程序。
这里有一篇关于同样问题的类似帖子,但回复并没有让我找到解决方案。
输出显示“来自 bytebuddy:agent premain”,但未显示“来自 bytebuddy:transform”。相反,日志显示属于引导类加载器的许多类的异常,例如:
Event::onError(org.mule.weave.v2.el.WeaveExpressionLanguage, org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader@6d4b1d14, null, false)
java.lang.IllegalStateException: Cannot resolve type description for java.lang.Exception
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.getSuperClass(TypeDescription.java:8031)
at net.bytebuddy.description.type.TypeDescription$Generic$OfNonGenericType.getSuperClass(TypeDescription.java:3619)
at net.bytebuddy.description.type.TypeDefinition$SuperClassIterator.next(TypeDefinition.java:314)
at net.bytebuddy.description.type.TypeDefinition$SuperClassIterator.next(TypeDefinition.java:281)
at net.bytebuddy.matcher.HasSuperTypeMatcher.matches(HasSuperTypeMatcher.java:53)
...
似乎正在查询类型描述的类加载器没有提供所需的类。ClassFileLocator
有没有办法为这些查找指定替代方案?
导致错误的特定类加载器是:
org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader
有趣的是,当使用 Byteman 作为代理时,该工具按预期工作,具有以下规则文件:
RULE AsyncHttpClientConfig.Builder.<init>
CLASS com.ning.http.client.AsyncHttpClientConfig$Builder
METHOD <init>
AT EXIT
IF TRUE
DO
traceln("from byteman: AsyncHttpClientConfig$Builder.<init> triggered: " + getClass().getClassLoader());
ENDRULE
任何意见,将不胜感激!谢谢您的帮助!