问题描述
我试图拦截或建议构造函数调用如下:
new AgentBuilder.Default()
//.disableClassFormatChanges()
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.with(AgentBuilder.TypeStrategy.Default.REDEFINE)
.type(ElementMatchers.nameMatches("org.openqa.selenium.firefox.FirefoxDriver"))
.transform((builder,typeDescription,classLoader,module) -> builder
.constructor(ElementMatchers.any())
.intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.to(FirefoxDriverInterceptor.class))))
//.intercept(SuperMethodCall.INSTANCE.andThen(Advice.to(FirefoxDriverConstructorAdvice.class))))
拦截器:
@RuntimeType
public static void intercept(@Origin Constructor<?> constructor) {
System.out.println("Intercepted: " + constructor.getName());
}
建议:
@Advice.OnMethodExit
public static void after(//@Advice.This Object thisObject,@Advice.Origin String method,@Advice.AllArguments Object[] args
) {
logger.info("<----- instantiated firefoxwebdriver: {}",method);
}
尝试使用拦截器或建议时,抛出异常是:
java.lang.IllegalStateException: Cannot call super (or default) method for public org.openqa.selenium.firefox.FirefoxDriver(org.openqa.selenium.firefox.GeckoDriverService,org.openqa.selenium.Capabilities)
at net.bytebuddy.implementation.SuperMethodCall$Appender.apply(SuperMethodCall.java:102)
at net.bytebuddy.implementation.bytecode.ByteCodeAppender$Compound.apply(ByteCodeAppender.java:134)
让我知道错误的指针。感谢您的帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)