问题描述
我正在 ByteBuddy 中“手动”构建一个方法。我正在构建的方法有一个 this.route.queryParams.pipe(
switchMap(({id}) => {
return this.formService.getFormFieldValById(id);
})
).subscribe(res => {
// bind response to form
})
类型的参数。假设它看起来像这样:
ProductType
在该方法中,我正在构建相当于:
public ProductType frob(ProductType product) {
// stuff that I'm implementing and asking about goes here
}
当我像这样构建 product.foo(); // more on this below; foo() has a void return type,which may be important
return product; // FixedValue.argument(0)
时,这很好用:
Implementation
(希望我输入正确。)
但是,如果我像这样构建一个 MethodCall.invoke(fooMethodDescription) // invoke foo()...
.onArgument(0) // ...on product...
.andThen(FixedValue.argument(0)); // ...and then return product
:
Implementation
...当然,如果使用正确的 InvokeDynamic.bootstrap(...) // look up foo()'s MethodHandle via my bootstrap method...
.invoke("foo",TypeDescription.VOID) // ...invoke the method handle with a return type of void...
.withArgument(0) // ..."on" the first and only argument (product) and "with" no other arguments...
.andThen(FixedValue.argument(0)); // ...and then return product
配方,由于 InvokeDynamic
错误 (Operand stack underflow
) 导致无法验证生成的类。
我有一个类似的 Attempt to pop empty stack
配方,在其他地方的很多地方都使用过,所以我知道我的问题不在于 InvokeDynamic
的用法。相反,它似乎与作曲有关?可能是?尽管 InvokeDynamic
和 MethodCall
都是 InvokeDynamic
,但它们的行为是否可能不同?也许 Implementation
不会在操作数堆栈上压入一些东西(也许只是在 InvokeDynamic
返回的情况下?)而 void
会吗?我在 MethodCall
用法中遗漏了什么?
使用 ByteBuddy 1.11.2。
解决方法
正如您正确指出的,这是 Byte Buddy 中的一个错误,现已修复。感谢那。它将随 1.11.3 版本一起发布。