Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

BackgroundFunctionExecutor.java failes to detect type when sub-classed

オープン
#95 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java
領域
backend, cloud

調査の方向性

BackgroundFunctionExecutor.java の 140 行目から始めて、backgroundFunctionTypeArgument を調べます。issue で説明されている MyExtendedBackgroundFunction と MyFunctionHandler の階層を再現し、そのうえで executor が MyReturnType を検出し、直接実装された BackgroundFunction 型に対する動作を維持することを確認します。

索引モデルが issue の本文から書いたものです。

説明

bug P3

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") &amp;&amp; m.getParameterCount() == 2            && m.getParameterTypes()[1] == Context.class            &amp;&amp; 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 はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

GoogleCloudPlatform/functions-framework-java のほかの issue

GoogleCloudPlatform/functions-framework-java の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。