Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

BackgroundFunctionExecutor.java failes to detect type when sub-classed

Ouverte
#95 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
38/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
java
Domaine
backend, cloud

Piste de recherche

Commencez dans BackgroundFunctionExecutor.java à la ligne 140 et examinez backgroundFunctionTypeArgument. Reproduisez la hiérarchie MyExtendedBackgroundFunction et MyFunctionHandler décrite dans l’issue, puis vérifiez que l’exécuteur détecte MyReturnType tout en préservant le comportement pour les types BackgroundFunction implémentés directement.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Java
Étoiles
154
Forks
63
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de GoogleCloudPlatform/functions-framework-java

Toutes les issues de GoogleCloudPlatform/functions-framework-java

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.