BackgroundFunctionExecutor.java failes to detect type when sub-classed
还没有人认领这个 Issue。
评估
调研方向
从 BackgroundFunctionExecutor.java 第 140 行开始,检查 backgroundFunctionTypeArgument。复现 issue 中描述的 MyExtendedBackgroundFunction 和 MyFunctionHandler 层次结构,然后验证 executor 能检测到 MyReturnType,同时保留对直接实现的 BackgroundFunction 类型的行为。
由索引模型根据 Issue 内容生成。
描述
Error Condition
Exception in thread "main" java.lang.RuntimeException: Could not determine the payload type for BackgroundFunction of type com.example.MyFunctionHandler; must implement BackgroundFunction for some T at com.google.cloud.functions.invoker.BackgroundFunctionExecutor.forClass(BackgroundFunctionExecutor.java:140) at com.google.cloud.functions.invoker.BackgroundFunctionExecutor.forClass(BackgroundFunctionExecutor.java:113) at com.google.cloud.functions.invoker.runner.Invoker.startServer(Invoker.java:256) at com.google.cloud.functions.invoker.runner.Invoker.main(Invoker.java:127)
Occurs when BackgroundFunction<T> is subclassed:
public abstract class MyExtendedBackgroundFunction<T> implements BackgroundFunction<T>
and
public class MyFunctionHandler extends MyExtendedBackgroundFunction<MyReturnType>
In the class mentioned, the following function fails to detect sub-classed BackgroundFunction type:
static Optional<Type> backgroundFunctionTypeArgument(Class<? extends BackgroundFunction<?>> functionClass) {
// If this is BackgroundFunction<Foo> then the user must have implemented a method
// accept(Foo, Context), so we look for that method and return the type of its first argument.
// We must be careful because the compiler will also have added a synthetic method
// accept(Object, Context).
return Arrays.stream(functionClass.getMethods())
.filter(m -> m.getName().equals("accept") && m.getParameterCount() == 2 && m.getParameterTypes()[1] == Context.class && m.getParameterTypes()[0] != Object.class)
.map(m -> m.getGenericParameterTypes()[0])
.findFirst();
}
This fails for described MyFunctionHandler.
The intent is to add common boilerplate handling for a couple of functions which is common to all. A separate abstract function is employed, but the function fails to load because the type is not determined.
Temporary workaround is to re-implement accept() with the type in the sub-classed object with the type, but is inelegant.
- 主要语言
- Java
- 星标
- 154
- 派生
- 63
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
GoogleCloudPlatform/functions-framework-java 的其他 Issue
-
enhancement P2
难度 1/5 1 小时以内 新手友好度 65/100
-
enhancement
GoogleCloudPlatform/functions-framework-java#375 · 1 条评论 · 1 个 reaction · 已指派 1 人 ·
-
enhancement P2
难度 5/5 一周以上 新手友好度 30/100
GoogleCloudPlatform/functions-framework-java#372 · 1 条评论 ·
-
enhancement P3
GoogleCloudPlatform/functions-framework-java#261 · 已指派 1 人 ·
-
P3 question
难度 4/5 3-5 天 新手友好度 35/100
GoogleCloudPlatform/functions-framework-java#254 · 1 条评论 ·
查看 GoogleCloudPlatform/functions-framework-java 的全部 Issue
相似的 Issue
-
certification
难度 1/5 1 小时以内 新手友好度 80/100
-
难度 2/5 1-3 小时 新手友好度 75/100
-
[BUG] ECR GetAuthorizationToken returns a proxyEndpoint for the default region, not the request's 未关闭bug ecr
难度 2/5 1-3 小时 新手友好度 75/100
-
Needs: Triage Type: Feature request
难度 2/5 1-3 小时 新手友好度 70/100
AntennaPod/AntennaPod#8794 ·
-
agentic-workflows
难度 2/5 1-3 小时 新手友好度 65/100
github/copilot-sdk#2760 ·