BackgroundFunctionExecutor.java failes to detect type when sub-classed
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 38/100
Hướng nghiên cứu
Bắt đầu trong BackgroundFunctionExecutor.java tại dòng 140 và kiểm tra backgroundFunctionTypeArgument. Tái hiện cấu trúc phân cấp MyExtendedBackgroundFunction và MyFunctionHandler được mô tả trong issue, sau đó xác minh rằng executor phát hiện MyReturnType đồng thời vẫn giữ nguyên hành vi đối với các kiểu BackgroundFunction được triển khai trực tiếp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Java
- Star
- 154
- Fork
- 63
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của GoogleCloudPlatform/functions-framework-java
-
enhancement P2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
-
enhancement
GoogleCloudPlatform/functions-framework-java#375 · 1 bình luận · 1 reaction · 1 người được giao ·
-
enhancement P2
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
GoogleCloudPlatform/functions-framework-java#372 · 1 bình luận ·
-
enhancement P3
GoogleCloudPlatform/functions-framework-java#261 · 1 người được giao ·
-
How to run `google/fhir-data-pipes/pipelines/batch` uber JAR in Google Cloud Functions locally? Đang mởP3 question
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
GoogleCloudPlatform/functions-framework-java#254 · 1 bình luận ·
Tất cả issue của GoogleCloudPlatform/functions-framework-java
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
elastic/gradle-plugins#157 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
cryptomator/hub#497 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
johanhaleby/occurrent#1120 ·