BackgroundFunctionExecutor.java failes to detect type when sub-classed
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 38/100
Direzione di ricerca
Inizia in BackgroundFunctionExecutor.java alla riga 140 e analizza backgroundFunctionTypeArgument. Riproduci la gerarchia di MyExtendedBackgroundFunction e MyFunctionHandler descritta nell’issue, quindi verifica che l’executor rilevi MyReturnType mantenendo il comportamento per i tipi BackgroundFunction implementati direttamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Java
- Stelle
- 154
- Fork
- 63
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di GoogleCloudPlatform/functions-framework-java
-
enhancement P2
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
-
enhancement
GoogleCloudPlatform/functions-framework-java#375 · 1 commento · 1 reazione · 1 assegnatario ·
-
enhancement P2
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
GoogleCloudPlatform/functions-framework-java#372 · 1 commento ·
-
enhancement P3
GoogleCloudPlatform/functions-framework-java#261 · 1 assegnatario ·
-
How to run `google/fhir-data-pipes/pipelines/batch` uber JAR in Google Cloud Functions locally? ApertaP3 question
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
GoogleCloudPlatform/functions-framework-java#254 · 1 commento ·
Tutte le issue di GoogleCloudPlatform/functions-framework-java
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
elastic/gradle-plugins#157 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
cryptomator/hub#497 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
johanhaleby/occurrent#1120 ·