BackgroundFunctionExecutor.java failes to detect type when sub-classed
まだ誰も着手していません。
評価
調査の方向性
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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
GoogleCloudPlatform/functions-framework-java のほかの issue
-
enhancement P2
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
-
enhancement
GoogleCloudPlatform/functions-framework-java#375 · コメント 1 件 · リアクション 1 件 · 担当者 1 名 ·
-
enhancement P2
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
GoogleCloudPlatform/functions-framework-java#372 · コメント 1 件 ·
-
enhancement P3
GoogleCloudPlatform/functions-framework-java#261 · 担当者 1 名 ·
-
How to run `google/fhir-data-pipes/pipelines/batch` uber JAR in Google Cloud Functions locally? オープンP3 question
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
GoogleCloudPlatform/functions-framework-java#254 · コメント 1 件 ·
GoogleCloudPlatform/functions-framework-java の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
elastic/gradle-plugins#157 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
cryptomator/hub#497 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
johanhaleby/occurrent#1120 ·